gpt4 book ai didi

amazon-web-services - 将 AWS S3 API 与 React Native 结合使用

转载 作者:行者123 更新时间:2023-12-03 14:28:22 27 4
gpt4 key购买 nike

我正在学习 React Native,我之前玩过 AWS S3,我在我的存储桶中设置了一些图像,我想从我的代码中执行 GET,并且该图像设置为私有(private)。

我想使用 React Native 方式调用 S3 API,就像我在 Angular2 项目中所做的那样。我上网查了一下,发现有第三方插件可以用来上传图片到S3。

我如何能够在react native中创建一个新的S3对象var s3 = new AWS.S3();并调用像s3.listBuckets(function(err,数据) {
if (err) console.log(err, err.stack);//发生错误
否则console.log(数据);//成功响应
});
或者只是在我的存储桶上获取私有(private)图像。

非常感谢!

最佳答案

AWS 官方存储库上的新 AWS Amplify 库现已提供此功能:https://github.com/aws/aws-amplify

您可以使用存储模块:https://github.com/aws/aws-amplify/blob/master/media/storage_guide.md

import { Storage } from 'aws-amplify'
Storage.configure( { level: 'private' } );
Storage.get('myfile.gif');

这是私有(private)图像的示例,但您可以使用库做更多事情。它还将使用与 Amazon Cognito 集成的 Auth 模块中处于已验证或未验证状态的用户的凭证。

关于amazon-web-services - 将 AWS S3 API 与 React Native 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43190595/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com