react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[fetch] FormData feature support detection broken

Open oblador opened this issue 11 years ago • 7 comments

I'm trying to post multipart files with fetch in RN 0.9.0 with something similar to this:

var formdata = new FormData();
formdata.append('image', this.state.image); // From camera roll or whatever
fetch('http://…', { method: 'POST', body: formdata });

It fails because the FormData feature detection always fails, more specifically 'FormData' in self on line 165 @ fetch.js. If I change self to window it works as expected, but somehow that feels too easy. I'm happy to send a PR or for someone to tell me why it's a bad idea.

oblador avatar Aug 18 '15 15:08 oblador

Same issue with that, support.formData and support.blob always false, but both FormData, Blob and FileReader exist in windows.

apolkingg8 avatar Aug 28 '15 03:08 apolkingg8

I'm having this same issue. You are right about self.fetch being the issue

peterpme avatar Sep 04 '15 00:09 peterpme

I am having the same issue, @oblador 's fix solved the problem.

jhau avatar Sep 07 '15 02:09 jhau

This would be a great fix to merge

jim-lake avatar Sep 09 '15 03:09 jim-lake

:+1: definitely, at the moment I need to use template strings for the body.

One thing to consider is that fetch is pulled in from github/fetch, meaning if it's updated in the future, all changes local to this repo are lost and would have to be reapplied.

Probably better to include it there, though they seem reluctant to include it. On the other hand, maybe fetch was only initially imported and is now maintained by the react-native team.

despairblue avatar Sep 09 '15 12:09 despairblue

I'm having the same issue as well. @oblador's fix also worked for me.

slooker avatar Sep 22 '15 15:09 slooker

My PR was recently merged, so I'm closing this issue.

oblador avatar Sep 23 '15 20:09 oblador