简体   繁体   English

将文件从浏览器上传到S3

[英]Upload files from browser to S3

I have a pre signed url that allows you to PUT documents objects into S3. 我有一个预签名的url,它允许您将对象文档放入S3。 http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjectPreSignedURLDotNetSDK.html http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjectPreSignedURLDotNetSDK.html

How do I put a file from the browser to S3 using javascript? 如何使用javascript将文件从浏览器放置到S3? I am using angular, but I am open to using any javascript library. 我正在使用angular,但可以使用任何JavaScript库。

I believe I could POST to my server, and then PUT the object on the amazon server, but I would prefer to do it from the browser. 我相信我可以发布到我的服务器上,然后将对象放在亚马逊服务器上,但是我更喜欢从浏览器中进行操作。

I have changed the CORS settings on S3 to allow PUTs. 我已经更改了S3的CORS设置以允许PUT。

I was planning to use angular file upload, but it is hard coded to POST not PUT. 我打算使用角度文件上传,但是很难将其编码为POST而不是PUT。 https://github.com/danialfarid/angular-file-upload https://github.com/danialfarid/angular-file-upload

Amazon has a guide ( here ) that describes how to POST-upload a file into your S3 bucket. 亚马逊提供了一个指南( here ),该指南描述了如何将文件POST上传到您的S3存储桶中。 It relies on an input <form> signed with your AWS private key. 它依赖于使用您的AWS私钥签名的输入<form>。 You can specify restrictions on the target directory, as well as file-size restrictions. 您可以在目标目录上指定限制,以及文件大小限制。

It's a bit annoying to use, because you have to duplicate most of the fields in both the <form> and the signed policy, but it seems to work. 使用起来有点烦人,因为您必须复制<form>和已签名策略中的大多数字段,但这似乎可行。

After the POST, S3 will redirect the browser to a URL you specify in the form (with parameters specifying the name of the uploaded file, etc.). POST之后,S3会将浏览器重定向到您在表格中指定的URL(参数指定上传文件的名称,等等)。 This isn't ideal for Angular web sites, which tend to be "applications" rather than a set of discrete pages, but you could probably work with it. 对于Angular网站(这往往是“应用程序”而不是一组离散页面)而言,这不是理想的选择,但是您可以使用它。

On my Angular site, I did the POST in Javascript using $http.post() and passed all the appropriate form data. 在我的Angular网站上,我使用$ http.post()在Javascript中进行了POST,并传递了所有适当的表单数据。 Unfortunately, I was always getting "cancelled" errors, even though the uploads were actually successful. 不幸的是,即使上传实际上是成功的,我也总是遇到“已取消”的错误。 In my case, I just double-checked by downloading the file with $http.get() and comparing it to the original data... but this was only a viable solution because my files were only a couple of KB. 就我而言,我只是通过使用$ http.get()下载文件并将其与原始数据进行比较进行了双重检查……但这只是一个可行的解决方案,因为我的文件只有几个KB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用签名的上传URL从浏览器上传到S3失败 - Uploading to S3 from browser using signed upload URL fails 如何从浏览器下载图像并上传到Amazon S3 - How to download Image from browser & upload to Amazon S3 从浏览器直接将字符串上传到s3,而无需本地文件 - direct upload string from browser to s3 without local file 是否可以从浏览器上传亚马逊s3上的流? - Is it possible to upload stream on amazon s3 from browser? S3使用预先签名的URL从浏览器上传图片 - S3 Upload image with pre-signed url from browser 使用 POST 直接从浏览器上传文件到 S3 - Upload file to S3 direct from the browser using POST 尝试使用 fetch 从浏览器通过 signedUrl 上传图像 S3,但图像在 s3 中为空白 - Trying to upload an image S3 via a signedUrl from a browser using fetch but the image is blank in s3 如何在浏览器中使用 javascript sdk 在 aws s3 存储桶中上传多部分文件 - How to upload multipart files in aws s3 bucket using javascript sdk in browser 使用aws js sdk,无需使用cognito,即可将浏览器中的大文件(&gt; 10GB)直接从浏览器安全地分段上传到s3 - Secure multi-part Upload of large files(>10GB) directly from browser to s3 using aws js sdk without using cognito 如何使用Meteor将文件上传到Amazon S3? - How to upload files to Amazon S3 with Meteor?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM