itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.9k stars 961 forks source link

Feature Request: Upload file support? #50

Closed wootwoot1234 closed 7 years ago

wootwoot1234 commented 8 years ago

Just as the title suggests, is file uploading on the roadmap? Thanks.

johanneslumpe commented 8 years ago

@wootwoot1234 As of now it isn't. A quick search brought up https://github.com/kamilkp/react-native-file-transfer and https://github.com/booxood/react-native-file-upload - did you try those modules out? Is there any specific reason to not use those modules?

wootwoot1234 commented 8 years ago

@johanneslumpe Yes, I looked into using both of those but because they didn't report back the progress (percentage uploaded). I asked if you were planning on supporting uploading because I already use this module (thanks for that BTW) and thought it would be a good fit. In the end, I created my own (or heavily modified react-native-file-upload) with progress reporting. I you're interested, you can add my code to react-native-fs. Here's a link to my module: https://github.com/wootwoot1234/react-native-transfer

johanneslumpe commented 8 years ago

@wootwoot1234 Would you like to submit a PR for this?

wootwoot1234 commented 8 years ago

@johanneslumpe I'm finishing up another project I was pulled into but will get started on a pull-request today I hope. I'll keep you updated.

mcorb commented 8 years ago

The built-in fetch() and XMLHttpRequest in react-native has fully-featured file upload support including progress status, and it works great alongside RNFS. Just specify the local file url as FormData and it will get uploaded with POST or PUT requests.

Please don't add another redundant implementation to RNFS unless it can do something core react-native can't. And if there's additional functionality, consider submitting it as an enhancement to the core?

rpopovici commented 8 years ago

@mcorb I don't know about the RN built-in upload support. I couldn't make it work for my use case and I had to relay on third party implementations. Anyway, having a pure native implementation doesn't hurt since this will offload the JS thread entirely and will give more space for further customization and bug fixing to your liking.

mcorb commented 8 years ago

@rpopovici Built-in XHR is offloaded and uploads in a native thread if you pass it a local file URL. There are hundreds of people contributing so it's well-specified and tested on both iOS and Android.

(A full featured download/upload manager with background support would of course be great but might be out of scope for this project?)

wootwoot1234 commented 8 years ago

@mcorb do you have an example of the fetch file uploading in react native? I wouldn't have spent the time creating a pull-request for fs with uploading if I had known it was already possible. I guess one thing that is nice with my code is that it can upload multiple files with one call or is that possible with fetch too?

mcorb commented 8 years ago

@wootwoot1234 Yeah, I'd love such a download library too. Just observing that it's a complex task to achieve equivalent/portable semantics on Android/iOS.

Here's a raw example from the react-native sources (https://github.com/facebook/react-native/blob/master/Libraries/Network/FormData.js). File upload works with fetch() too which is the form you'll probably want to use.

It'd be cool to document that upload of files is already possible in the RNFS README, perhaps you could make a pull request once you verify fetch() works?

/**

wootwoot1234 commented 8 years ago

@mcorb I think adding that to the readme would be good. It would keep people from going down the same path I did. Can fetch do downloading too?

@johanneslumpe are you still interested in the upload files pull request I did. I have time to clean it up right now or would you rather just suggest people use fetch?

mcorb commented 8 years ago

@wootwoot1234 Pretty sure react-native core doesn't have download-to-file support yet, you need a third-party library for that. They were waiting on someone to specify a sane API, probably involving fetch(r => r.blob())

There are a lot of half-working/single-platform RN download libs on GitHub right now, would be great to consolidate work and nudge RN core to get a decent download solution so RNFS can focus on the filesystem

rpopovici commented 8 years ago

@mcorb Is it the RN uploader working with any kind of files or is it working only with images? I am asking this because I don't have time to test it right now, and I might have to upload some PDFs at some point. Thanks!

johanneslumpe commented 8 years ago

@wootwoot1234 Have you tried out what @mcorb suggested? If uploading files is easily possible with react native's utilities, then I feel that this does not have to be included in RNFS. I'm open to further discussion regarding this.

wootwoot1234 commented 8 years ago

@johanneslumpe I haven't tried it. Looking at it a little closer it looks like it might support multiple files too. The only thing I couldn't tell from looking at the code is what type of file paths it supports. In other words, can you upload files from the main bundle, documents, and library directories?

johanneslumpe commented 8 years ago

@wootwoot1234 I haven't looked into that functionality at all. But if you can specify a URI, I'd assume that it accepts arbitrary file paths?!

rreusser commented 8 years ago

Random thought: Upload seems like a natural addition. https://github.com/PhilippKrone/react-native-fileupload is MIT licensed and the PRs need a bit of attention. Is it possible or reasonable to imagine merging some of that code into this module?

(Or for that matter, technically anything that is MIT licensed could be simply merged in without asking, though it's always nice to ask anyway :smile: )

johanneslumpe commented 8 years ago

@rreusser @wootwoot1234 I still haven't checked out react-native's internal upload functionality. Because if it supports all use-cases then there wouldn't be the need to add anything here. Did any of you try it?

timzaak commented 8 years ago

in react-native 0.26-release , android do not support upload.onprogress , ios has already supported.

sibelius commented 7 years ago

@johanneslumpe @mcorb is right, react native upload funcionality works fine, can we close this?

cc @wootwoot1234

wootwoot1234 commented 7 years ago

Does the react native upload functionality support all the file paths? If it does I think this can be closed, if it doesn't, I've been using my code in production for a while now and it works great.