[英]React-Native push to AWS S3
I am working on a React-Native App client that needs to generate a JSON file and send it to a s3 bucket.我正在开发一个需要生成 JSON 文件并将其发送到 s3 存储桶的 React-Native 应用程序客户端。 I don't quite know how to do the two steps of this process:
我不太清楚如何执行此过程的两个步骤:
First I'd need o be able to generate a JSON file with some variables from my App.首先,我需要能够从我的应用程序中生成带有一些变量的 JSON 文件。 For these I found https://www.npmjs.com/package/react-native-fs .
对于这些,我找到了 https://www.npmjs.com/package/react-native-fs 。 The problem is I don't quite know if it would work correctly, or even where it would save the file.
问题是我不太清楚它是否能正常工作,甚至不知道它将文件保存在哪里。 I wouldn't want to pollute the user's phone, and rather have the file be stored in a safe location.
我不想污染用户的手机,而是将文件存储在安全的位置。
Then I'd need to be able to send this file over to the S3 bucket.然后我需要能够将此文件发送到 S3 存储桶。 I think https://www.npmjs.com/package/react-native-aws3 is the best option, but I'm not sure if it is.
我认为https://www.npmjs.com/package/react-native-aws3是最好的选择,但我不确定是否是。
What would be the recommended way to do this?推荐的方法是什么?
Definitely using the official AWS Javascript SDK is the best way of doing it.绝对使用官方AWS Javascript SDK 是最好的方法。 As you may know react native lives in the javascript thread and so you can use already made javascript libraries and sdks.
如您所知,React Native 存在于 javascript 线程中,因此您可以使用已经制作的 javascript 库和 sdk。 ( This may not be always true but in this case it is )
(这可能并不总是正确的,但在这种情况下它是)
Take a look at this AWS article on how to use their Javascript SDK in react native. 看看这篇 AWS 文章,了解如何使用他们的 Javascript SDK 进行原生反应。
And then you could use this method in the sdk for uploading your JSON object to an S3 bucket without having to actually create the file in the device before uploading it.然后您可以在 sdk 中使用此方法将您的 JSON object 上传到 S3 存储桶,而无需在上传之前在设备中实际创建文件。 The sdk takes care of it for you.
sdk 为您处理。
s3.putObject({
Bucket: 'currenteventstest',
Key: 'users.json',
Body: JSON.stringify(users),
ContentType: "application/json"},
function (err,data) {
console.log(JSON.stringify(err) + " " + JSON.stringify(data));
}
);
Method for node js aws sdk for uploading a JSON object to S3 object 用于将 JSON object 上传到 S3 ZA8CFDE6331BD59EB66AC96F8911C4 的节点 js aws sdk 的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.