Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
Download a S3 file

Im building a webapp using AWS S3.

Question: How can I download a file from S3 and save the file in the users Downloads folder?

My code so far:

this.getS3().getObject({Bucket:bucket_name, Key:keys},
      function(error, data) {
        if (error) {
          console.log("Error!")
        } else {
          // How to save 'data' file in Download folder?
        }
      });
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is how i am doing in .NET using the AWS SDK for .Net

public class AmazonS3
    {
        //Local varaibles to get the accesskey and secretkey
        private readonly string accessKey;
        private readonly string secretKey;
        private RegionEndpoint regionEndpoint;
        AmazonS3Client client = null;
        TransferUtility utility = null;

        /// <summary>
        /// Class Constructor for getting the accesskey and secretkey for the Amazon S3 bucket
        /// </summary>
        public AmazonS3Operations()
        {
            //get the accesskey and secretkey from the web.config

            accessKey = ConfigurationManager.AppSettings["AWSS3AccessKey"];
            secretKey = ConfigurationManager.AppSettings["AWSS3SecretKey"];
            regionEndpoint = RegionEndpoint.GetBySystemName(ConfigurationManager.AppSettings["AWSS3RegionEndPoint"]);

            //Initialize the connection here and use it every where in a singleton model
            client = GetS3ClientConnection();
        }

public byte[] GetFileObject(string filePath, string fileNameInS3, out string strContentType)
        {
            byte[] data = null;

            GetObjectRequest request = new GetObjectRequest();
            request.BucketName = filePath;
            request.Key = fileNameInS3;

            //get the object response here
            GetObjectResponse response = client.GetObject(request);
            using (MemoryStream ms = new MemoryStream())
            {
                response.ResponseStream.CopyTo(ms);
                data = ms.ToArray();
            }
            //get the Mimetype here                
            strContentType = MimeMapping.GetMimeMapping(fileNameInS3);
            return data;

        }

}

Pass your parameters to the method GetFileObject which returns the byte[] array in response. Create the respective file with the respective name and MIME type in the users download folder.

Refer here for doing the same with Java : http://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingJava.html

There are other AWS documents available online too for other languages.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda