0

I'm developing a web app that upload images and other files regularly.I'm using AWS Cognito service as authentication method.Uploading using PHP SDK is not working for me since I use JavaScript and HTML5. Can anybody give me a complete example of authenticating AWS S3 using Cognito and upload images and retrieve the preview of uploaded image when success, using JavaScript.

2
  • 1
    Show what you have tried. Commented Aug 20, 2017 at 18:42
  • i did try several methods but non of those work.even i couldn't find any example either .appreciate if you can help me. Commented Aug 21, 2017 at 16:31

2 Answers 2

1

You can use, AWS CloudFront Signed URLs with AWS PHP SDK to generate Signed URLs to perform the upload directly from Browser using AWS JavaScript SDK for S3.

getSignedUrl ( string $url, string|integer|null $expires = null, string $policy = null )

The flow involved is from the browser, you will request for a url, with an expiration time, to allow upload a file to a bucket. You can write Sign url creation using PHP Backend and AWS SDK as given in this example, after authenticating the user.

Using the Signed URL and AWS JavaScript SDK for S3, browser can directly upload the file to S3.

For more information about Signed URLs, check how Signed URLs Work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank Ashan for the response.i'm stuck for days now.can you provide some basic example.i'm very new to AWS .is this method call as HTTP post as well ..? i need to upload up to at least 150mb files.seems like your answer is right but i'm not clear..!
0

Thanks all ,i found the correct answer in this link.

http://www.tothenew.com/blog/aws-s3-file-upload-with-progress-bar-using-javascript-sdk/

3 Comments

The sample link, require a public bucket, which can cause security concerns. I would recommend to use Signed URLs in addition.
IS there anyway i can make this link " tothenew.com/blog/… " Authenticate with cognito ..? because i don't found any example in signed URL.
Dear Ashan, can you help on this matter please.I already genarate Presingned Url but One Error Occured .stackoverflow.com/questions/45854564/aws-pre-signed-url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.