Skip to content

Instantly share code, notes, and snippets.

@EQuimper
Created October 3, 2016 15:18
Show Gist options
  • Select an option

  • Save EQuimper/464e09e9101b6977e9c4e25470d6679d to your computer and use it in GitHub Desktop.

Select an option

Save EQuimper/464e09e9101b6977e9c4e25470d6679d to your computer and use it in GitHub Desktop.
Upload React-Native photo to server
const photo = {
uri: image,
type: 'image/jpeg',
name: 'avatar.jpg',
};
/* globals FormData */
const data = new FormData();
data.append('avatar', photo);
const options = {
body: data,
headers: {
...api.headers,
'Content-Type': 'multipart/form-data'
},
method: 'POST',
};
const res = await fetch('/upload', options)
@koswarabilly
Copy link
Copy Markdown

@sunnynegi maybe because of the url your are sending too, localhost:port is an invalid request because you do not let them to use the default port but you do not define any port yourself

@sunnynegi
Copy link
Copy Markdown

@koswarabilly Well thanks for suggestion, Problem is solved i am using fecth blob for uploading images.

@osinakayah
Copy link
Copy Markdown

@sunnynegi Can u please post your code sample for uploading?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment