Amazon S3 upload file and get URL

后端 未结 9 1538
醉酒成梦
醉酒成梦 2020-12-23 03:05

Is it possible to upload a txt/pdf/png file to Amazon S3 in a single action, and get the uploaded file URL as the response. If so, is AWS Java SDK the right library that I n

9条回答
  •  春和景丽
    2020-12-23 03:30

    For AWS SDK 2+

    String key = "filePath";
    String bucketName = "bucketName";
    PutObjectResponse response = s3Client
                .putObject(PutObjectRequest.builder().bucket(bucketName ).key(key).build(), RequestBody.fromFile(file));
     GetUrlRequest request = GetUrlRequest.builder().bucket(bucketName ).key(key).build();
     String url = s3Client.utilities().getUrl(request).toExternalForm();
    

提交回复
热议问题