AWS S3 Java SDK - Download file help

前端 未结 5 1510
臣服心动
臣服心动 2020-12-13 03:59

The code below only works for downloading text files from a bucket in S3. This does not work for an image. Is there an easier way to manage downloads/types using the AWS S

5条回答
  •  鱼传尺愫
    2020-12-13 04:46

    Though the code written in Mauricio's answer will work - and his point about streams is of course correct - Amazon offers a quicker way to save files in their SDK. I don't know if it wasn't available in 2011 or not, but it is now.

    AmazonS3Client s3Client = new AmazonS3Client(myCredentials);
    
    File localFile = new File("localFilename");
    
    ObjectMetadata object = s3Client.getObject(new GetObjectRequest("bucket", "s3FileName"), localFile);
    

提交回复
热议问题