AWS S3 Java SDK - Download file help

前端 未结 5 1513
臣服心动
臣服心动 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:51

    Eyals answer gets you half way there but its not all that clear so I will clarify.

    AmazonS3Client s3Client = new AmazonS3Client(myCredentials);
    
    //This is where the downloaded file will be saved
    File localFile = new File("localFilename");
    
    //This returns an ObjectMetadata file but you don't have to use this if you don't want 
    s3Client.getObject(new GetObjectRequest(bucketName, id.getId()), localFile);
    
    //Now your file will have your image saved 
    boolean success = localFile.exists() && localFile.canRead(); 
    

提交回复
热议问题