简体   繁体   English

Angular.js和Amazon S3 - 如何上传文件?

[英]Angular.js and Amazon S3 - How to Upload files?

I have an application in Angular.js. 我在Angular.js中有一个应用程序。 In the truth, I made an update in my old site, changed that for Angular. 事实上,我在我的旧网站上做了更新,改为Angular。

In old version, I was using Uploadfy jquery component for my uploads in Amazon S3. 在旧版本中,我使用Uploadfy jquery组件来在Amazon S3中上传。 But now, with Angular, I can't use this. 但现在,有了Angular,我无法使用它。

I want to use the directive "ngUpload". 我想使用指令“ngUpload”。 But I don't know how to do this. 但我不知道该怎么做。 Anybody can help-me? 有人可以帮我吗?

You can upload directly to an S3 bucket from an HTML form if you include valid S3 parameters in your POST data. 如果在POST数据中包含有效的S3参数,则可以从HTML表单直接上载到S3存储桶。 These are called pre-authorized HTML POST forms. 这些被称为预授权的HTML POST表单。

The valid parameter values are generated on your own hosting server through an API call to the AWS API. 有效参数值是通过对AWS API的API调用在您自己的托管服务器上生成的。 The values are then added to your upload form as hidden input fields. 然后将值作为隐藏输入字段添加到上载表单中。

Here's what they look like in your form: 这是他们在您的表单中的样子:

  <input type="hidden" name="AWSAccessKeyId" value="YOUR_AWS_ACCESS_KEY"> 
  <input type="hidden" name="acl" value="private"> 
  <input type="hidden" name="success_action_redirect" value="http://yourdomain/">
  <input type="hidden" name="policy" value="YOUR_POLICY_DOCUMENT_BASE64_ENCODED">
  <input type="hidden" name="signature" value="YOUR_CALCULATED_SIGNATURE">

Amazon provides sample code for Java, Python and Ruby. 亚马逊提供Java,Python和Ruby的示例代码。

http://aws.amazon.com/articles/1434 http://aws.amazon.com/articles/1434

You can use angular-file-upload a lightweight angular directive which has support for file progress and file drop. 您可以使用angular-file-upload轻量级角度指令,该指令支持文件进度和文件丢弃。

You can follow the Amazon S3 issues here which has a sample code as how to send all those data along with the file upload: https://github.com/danialfarid/angular-file-upload/issues/23 您可以在此处关注Amazon S3问题,其中包含示例代码,以及如何将所有这些数据与文件上载一起发送: https//github.com/danialfarid/angular-file-upload/issues/23

S3 upload should work with version 1.1.1 above. S3上传应该适用于上面的1.1.1版。

another related issue: https://github.com/danialfarid/angular-file-upload/issues/23 另一个相关问题: https//github.com/danialfarid/angular-file-upload/issues/23

You can do this using a "public" IAM account and API key with the AWS JS SDK if you want to process the files after upload and move them elsewhere. 如果要在上载后处理文件并将其移动到其他位置,则可以使用AWS JS SDK中的“公共”IAM帐户和API密钥执行此操作。 For example, to process and store an uploaded file. 例如,处理和存储上载的文件。

Using Angular, AWS S3 JS SDK, CORS and IAM accounts. 使用Angular,AWS S3 JS SDK,CORS和IAM帐户。 There's a bit of setup involved to lock it down so it doesn't get abused though. 有一些设置涉及锁定它,所以它不会被滥用。

I'v documented the process of setting this up here: http://www.cheynewallace.com/uploading-to-s3-with-angularjs/ 我在这里记录了设置过程: http//www.cheynewallace.com/uploading-to-s3-with-angularjs/

一个如果最好的s3-file-upload angular指令带有动态数据绑定,回调函数 - https://github.com/vinayvnvv/s3FileUpload

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM