2
votes

I have a bucket with default ACL set to private. I want to generate pre signed url and distribute it to user so that they can upload the file and the file is needed to be publicly accessible after upload.

I can generate pre signed url and upload the file but the file always remains private. If i set ACL to 'public-read' while creating signed url then getSignedUrl() is generating a signed url but PUT request to that signed url throws access denied.

var params = {
    Bucket: "bucket name",
    Key: "file key name",
    Expires: 3600,
    ACL:"public-read",
    ContentType: "application/octet-stream"
};
s3.getSignedUrl("putObject", params);

The bucket can contain either private or publicly accessible files and i want to set the privacy while creating a signed url. How i can achieve this?

I am using amazon javascript sdk.

1

1 Answers

-1
votes

Here from the AWS-S3 docs...

Looks like you have to do it the hard way.

getSignedUrl(operation, params, callback) ⇒ String?
Note: You must ensure that you have static or previously resolved credentials if you
call this method synchronously (with no callback), otherwise it may not properly sign
the request. If you cannot guarantee this (you are using an asynchronous credential provider,
i.e., EC2 IAM roles), you should always call this method with an asynchronous callback.
Note: Not all operation parameters are supported when using pre-signed URLs. Certain parameters,
such as SSECustomerKey, ACL, Expires, ContentLength, or Tagging must be provided as headers when
sending a request.
If you are using pre-signed URLs to upload from a browser and need to use these fields,
see createPresignedPost()....