We are trying to create a JS MS Office add in that will let users save a document to an S3 bucket, however I am not seeing any way to do that. Has anyone had any success getting this to wrok?
You can use the Amazon SDK for JavaScript to interact with an Amazon S3 bucket. See Uploading Photos to Amazon S3 from a Browser for more information. Don't forget to configure CORS correctly as described in the article mentioned.
Related
Sorry if this is a silly question since I know that AWS has an article on how to do this with AWS Amplify: here
But I want to do this work with AWS SAM and it seems AWS SAM doesn't support many services including AWS Amplify.
If someone can just point me in the right direction or let me know that it is not possible, I'd appreciate it.
I can't get the JavaScript part to work with API Gateway
You can start with one of two ways described below.
First: AWS S3 Website Hosting
NOTE: You can't configure custom domain with this scenario and below instruction is simplified. Visit documentation page for more details.
Create AWS S3 bucket, upload HTML, CSS and JS sources and enabled Static Website Hosting in S3 bucket's Properties.
Using AWS Console:
Open your S3 Bucket
Navigate to Bucket Properties
Under Static website hosting choose Edit
In Index document enter file name of index document, typically index.html.
(Optional, more info in documentation) You can provide custom document for 4XX class errors
Save changes
Under Static website hosting there will be your website endpoint.
Ref: https://docs.aws.amazon.com/AmazonS3/latest/userguide/EnableWebsiteHosting.html
Second: AWS S3 + CloudFront
NOTE: You can have custom domain with this scenario.
There are couple of options to consider, so read the details in AWS documentation: https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-serve-static-website/
I'm new to web development and server requests, I have a url to an amazon s3 bucket and I have all the required values, such as key, policy, security token, signature, and the file I want to upload etc. I was wondering how I would actually upload the file to the s3 bucket in javascript. Would I use:
$.post, or something else and what would the parameters be for the request and the format. Currently I keep getting error 412 or 403.
Thanks
I would suggest using the AWS Javascript SDK which is a library of functions for interacting with AWS service endpoints. If you attempt to post directly to a service endpoint or s3 URL then you will be expected to have signed the call using the standard AWS Signature v4 which can be hard to implement and is done for you in the SDK libraries.
The SDK will also correctly integrate with IAM permissions which you typically need to have correctly setup to write to a bucket.
A full example is provided here
I have a static website hosted on an S3 bucket. The website takes a file as an input and uploads it to another S3 bucket. I don't want to keep the bucket as public. How can I upload a file to a non-public bucket? Currently, I'm using my access key to upload a file, but I don't want to expose the access key in my Javascript code for authentication. My objective is to upload a file to a non-public bucket without exposing my access credentials.
Edit1:
I used the amazon API gateway with Lambda to generate pre-signed S3 URL. This way my credentials don't get exposed.
You can use environment variables to hide API Keys for Javascript. React and Node examples
You could also use AWS Parameter Store to store the API Keys. There are examples of how to integrate with node.js and other frameworks.
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.
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/
I'm using the javascript SDK for AWS s3. I'm attempting to upload a file to my bucket and right after that, getting that file data from S3. So i'm facing two issues :
I need to execute synchronously two functions. One for uploading and another to fetch the file's data. I am using the Client javascript SDK for aws S3 and i don't know how to be sure to have all files fully uploaded before starting to fetch them in the bucket.
Also, the object data does not show the url of the file , so i don't know how to get it.
Please any help would be appreciated.