benjreinhart / react-native-aws3

Pure JavaScript React Native library for uploading to AWS S3
MIT License
400 stars 151 forks source link

Suggestions for web? #4

Closed kennetpostigo closed 8 years ago

kennetpostigo commented 8 years ago

Would you have any suggestions for a react web aws3 uploader library? Want to use something with a similar API to this but for the web. As an application i'm working on will be a webapp and react native app (Android & iOS)

benjreinhart commented 8 years ago

I'm not sure for react specifically, though there are plenty solutions for uploading via web, including Amazon's own client.

This could be extended for the web fairly easily, but I don't have plans to do so at the moment.

kennetpostigo commented 8 years ago

@benjreinhart if you give me some information about what needs to be extended in the library I will gladly submit a PR as using one lib for both web and native clients would be great. Also great job on this library!

benjreinhart commented 8 years ago

@kennetpostigo I might be missing some things but here is my initial high-level thoughts. For web, I think it'd be pretty easy since we should not be generating signed urls on the client because that would require us to have the IAM user's secret key on the client. So I believe we may need the following features:

I'm guessing I'm missing something but that's what comes to mind.

joonhocho commented 8 years ago

@kennetpostigo, I am currently using the following repos on my project. https://github.com/joonhocho/s3-policy-middleware https://github.com/joonhocho/s3-policy-v4

I created these repos to generate s3 policy on the server side on Node.js. s3-policy-v4 is a simply refactored clone of react-native-aws3/src/S3Policy.js (thanks to @benjreinhart).

If you are using express, you can use s3-policy-middleware, which is a simple middleware wrapper around s3-policy-v4. If you are using node.js, but not express, then you can use s3-policy-v4 and create an endpoint yourself.

On the client side, you need to post to the endpoint with name and contentType (if you are using s3-policy-middleware), and you will receive the policy back in json format.

Then, you need to use the signed url that you receive with the policy to upload to s3 directly on the client side. I also have some code to upload to s3 using XMLHttpRequest which is available both on react native and web, but I haven't open sourced it yet. I will do it soon when I get some free time.

kennetpostigo commented 8 years ago

@benjreinhart Thanks for the information. I'll see if I can whip something up on my spare time.