简体   繁体   中英

AWS S3 Presigned URL file upload - Retain file name in bucket

I am trying to upload files into S3 bucket using presigned PUT URL like below

String tempFileKey = UUID.randomUUID().toString();
    GeneratePresignedUrlRequest generatePresignedUrlRequest =
                    new GeneratePresignedUrlRequest(tempBucketName, tempFileKey)
                            .withMethod(HttpMethod.PUT)
                            .withExpiration(expiration);
    URL fileUrl = s3Client.generatePresignedUrl(generatePresignedUrlRequest);

The problem with above approach is if the user uploads a file named 'xyz.jpg', I am not able to retain the file name (or extension) in the s3 bucket. The file gets saved with the tempFileKey as name. I won't be knowing the file name or extension while creating the presigned url.

I tried using ${filename} as tempFilekey as suggested in Sending file direct from browser to S3 but changing file name but it is just getting saved under the name ${filename} (literally)

Object key is integral part of the pre-signed url and is required by the algorithm which generates the url:

Thus, you can't change the key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM