简体   繁体   English

如何通过AWS Cognito使用ng-file-upload进行上传?

[英]How to upload using ng-file-upload with AWS Cognito?

I have AWS Cognito installed for my Angular application, and I am trying to hook in the s3.putObject some how into the ng-file-upload Upload service. 我已为Angular应用程序安装了AWS Cognito,并且尝试将s3.putObject挂接到ng-file-upload Upload服务中。

I want to use ng-file-upload's Upload.upload() method, but I don't know how to use the existing authenticated connection with Cognito. 我想使用ng-file-upload的Upload.upload()方法,但是我不知道如何在Cognito中使用现有的经过身份验证的连接。 The idea is to use ng-file-upload's drag and drop and then the upload will use the existing Cognito connection to upload to s3. 这个想法是使用ng-file-upload的拖放操作,然后上传将使用现有的Cognito连接上传到s3。 How can I do this? 我怎样才能做到这一点? The reason why I want to use ng-file-upload's Upload.upload() method is to help retain some of the functionality like progress bars (please correct me if this is incorrect). 我之所以要使用ng-file-upload的Upload.upload()方法,是为了帮助保留进度条之类的某些功能(如果不正确,请更正我)。

I assume you are trying to upload to S3 bucket directly from your client in Single Page App. 我假设您正在尝试直接从您的客户端在Single Page App中上载到S3存储桶。 If so, you can start by pre signing S3 URL and then try using it in ng-file-upload. 如果是这样,您可以先对S3 URL进行签名,然后尝试在ng-file-upload中使用它。 A pre-signed URL allows you to give one-off access to other users who may not have direct access to execute the operations. 通过预签名URL,您可以一次性授予其他可能无权直接执行操作的用户访问权限。 Pre-signing generates a valid URL signed with your credentials that any user can access. 预签名会生成一个使用您的凭据签名的有效URL,任何用户都可以访问。 By Default the URL's generated by the SDK expire after 15 minutes. 默认情况下,SDK生成的URL将在15分钟后失效。

To generate a simple pre-signed URL that allows any user to put object in a bucket you own, you can use the following call to getSignedUrl(): 要生成允许任何用户将对象放入您自己的存储桶中的简单预签名URL,可以使用以下调用getSignedUrl():

//Initialize the SDK with Cognito Credentials
var s3 = new AWS.S3();
var params = {Bucket: 'myBucket', Key: 'myKey'};
var url = s3.getSignedUrl('putObject', params);
console.log("Use this url in ng-file-upload", url);

For more information on getting pre signed URL, refer to this wiki http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-examples.html#Amazon_S3__Getting_a_pre-signed_URL_for_a_PUT_operation_with_a_specific_payload and consult ng-file-upload documentation 有关获取预签名URL的更多信息,请参阅此Wiki http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-examples.html#Amazon_S3__Getting_a_pre-signed_URL_for_a_PUT_operation_with_a_specific_payload并查阅ng文件上传文档

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

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