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.
-
1Show what you have tried.Priyal– Priyal2017-08-20 18:42:37 +00:00Commented 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.user4270323– user42703232017-08-21 16:31:16 +00:00Commented Aug 21, 2017 at 16:31
2 Answers
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.
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/