简体   繁体   中英

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. 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. For these I found 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. I think https://www.npmjs.com/package/react-native-aws3 is the best option, but I'm not sure if it is.

What would be the recommended way to do this?

Definitely using the official AWS Javascript SDK is the best way of doing it. As you may know react native lives in the javascript thread and so you can use already made javascript libraries and sdks. ( 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.

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. The sdk takes care of it for you.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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