Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presigned V4 URLs using Java SDK #834

Closed
mohamnag opened this issue Sep 2, 2016 · 20 comments
Closed

Presigned V4 URLs using Java SDK #834

mohamnag opened this issue Sep 2, 2016 · 20 comments
Labels
feature-request A feature should be added or improved.

Comments

@mohamnag
Copy link

mohamnag commented Sep 2, 2016

I have been trying to find a way to generate a presigned URL using SDK which also contain a policy document. However I found out that it is not possible as documented here:

Note that presigned URLs cannot be used to upload an object with an attached policy, as described in this blog post. That method is only suitable for POSTs from HTML forms by browsers.

My case is that I'm using SDK on a server that generates presigned URLs for clients. Then clients may use these to upload files to S3.

I would say there are a lot of cases where it is important to force specific content length or similar obligations on the request. So is this a final decision not to include policy signed URL generation in AWS SDK?

@zhangzhx zhangzhx added the feature-request A feature should be added or improved. label Sep 6, 2016
@zhangzhx zhangzhx self-assigned this Sep 6, 2016
@zhangzhx
Copy link
Contributor

zhangzhx commented Sep 6, 2016

Thanks for reaching out to us. This is a very interesting feature request. I will bring this feature request to our team and talk about it to see whether we want to support it.

@zhangzhx
Copy link
Contributor

zhangzhx commented Sep 6, 2016

Hey @mohamnag,

AWS Java SDK already supports this feature. See here.

Just use HttpMethod.PUT as the verb for generating the presigned URL. Here is the sample code:

GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key, HttpMethod.PUT);
URL url = s3.generatePresignedUrl(request);

HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod(request.getMethod().toString());
connection.setDoOutput(true);
connection.connect();

You can use connection.getOutputStream() to write the data you want to upload, ex the policy document.

@zhangzhx zhangzhx removed the feature-request A feature should be added or improved. label Sep 6, 2016
@mohamnag
Copy link
Author

mohamnag commented Sep 8, 2016

This is not what I was asking for. This uploads the file directly using Java SDK to S3.
What I want is to generate a presigned URL to give to a client which may or may not have access to any kind of AWS SDK but should be able to do a simple PUT or POST request to upload the file.

You currently have s3.generatePresignedUrl(request); but this does not support putting a policy document into the signed URL. The result is that client may do things that are not supposed to be possible, like uploading a file which is too big.

What I'm looking for is to impose limits inside the URL by attaching a policy document like what is described here only to do it completely on server side and just give client that final URL.

I already have a custom Java code that does so, but it would be nice to have it as part of SDK.

@shorea
Copy link
Contributor

shorea commented Sep 8, 2016

I'm not sure if presigned URLs support limiting content sizes, I'll have to ask the service team. If you know the exact content length you can always set that and it will be included in the signature but doesn't sound like it will help in this case.

@mohamnag
Copy link
Author

there is no exact one, but there is a max length. and yes it is possible. thats at least what that linked page says. It is only impossible to build URLs using AWS SDK. But as I said, one can reproduce the signing process and do it on his own.

@dagnir dagnir added the feature-request A feature should be added or improved. label Sep 28, 2016
@huantingchen
Copy link

There's a createPresignedPost() function in JS SDK. See below. It would be helpful if Java SDK supports this, too.
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createPresignedPost-property

@MatteCarra
Copy link

+1

@polarlights
Copy link

Some website service do not support uploading a file with their web component through "PUT" method.

@Manikanta220
Copy link

java.util.Date expiration = new java.util.Date();
long milliSeconds = expiration.getTime();
milliSeconds += 1000 * 60 * 30; // Add 20 mins.
expiration.setTime(milliSeconds);

		GeneratePresignedUrlRequest generatePresignedUrlRequest = 
			    new GeneratePresignedUrlRequest(bucketName, objectKey);
		generatePresignedUrlRequest.setMethod(HttpMethod.GET); 
		generatePresignedUrlRequest.setExpiration(expiration);

		URL url = s3client.generatePresignedUrl(generatePresignedUrlRequest); 

		System.out.println("Pre-Signed URL = " + url.toString());

@mleonhard
Copy link

Hi AWS SDK Team,
I also need the ability to limit the size of files uploaded via a pre-signed URL or request. Please consider implementing this.

Thanks,
Michael

@boweiliu
Copy link

Hi,

Python boto3 has this as well - https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-presigned-urls.html#generating-a-presigned-url-to-upload-a-file . Would be nice to have it in java.

@kamil-perczynski
Copy link

+1 It would great to have that method in Java SDK also
For anybody in urgent need: https://github.com/kamil-perczynski/s3-direct-browser-upload

@Hammond95
Copy link

Please implement this feature!

@bernardobelchior
Copy link

This would also be very useful for me! Is there any progress regarding this feature?
I'm currently trying to set a max size on a file upload, whose URL is generated in the backend.

@mohamnag
Copy link
Author

mohamnag commented Oct 8, 2020

yeah, "progress" for an issue thats open for past 4 years seems to be a heavy word. looks like AWS has actually no interest in implementing things that community wants just what's dictated from above!

@Milunas
Copy link

Milunas commented Dec 16, 2021

Hi! Do you know anything new about this feature? :)

@dz902
Copy link

dz902 commented Jun 8, 2022

Still no luck.

@dyegosutil
Copy link

dyegosutil commented Sep 15, 2023

Hello all 👋

I created this open source library to upload files to AWS S3 using Pre Signed POST. I am officially opening up for usability test.

With it you can specify requirements and restrictions that the client using the pre-signed post, generated by you, must
follow. The conditions can be the maximum size of the file, how the object key name should start with, encryption key and many others.

Feel free to check it out on github and maven central 👍

Cheers,
Dyego

@debora-ito
Copy link
Member

We apologize but this feature won't be added to v1.

Java SDK v2 doesn't support POST presigned urls either, please track the v2 feature request in aws/aws-sdk-java-v2#1493.

Reference:

  • Announcing end-of-support for AWS SDK for Java v1.x effective December 31, 2025 - blog post

@debora-ito debora-ito closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2024
Copy link

This issue is now closed.

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests