Skip to content

Instantly share code, notes, and snippets.

@whizkydee
Created December 12, 2018 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whizkydee/447472cf9d72d1f7d6860ab28b417a62 to your computer and use it in GitHub Desktop.
Save whizkydee/447472cf9d72d1f7d6860ab28b417a62 to your computer and use it in GitHub Desktop.
handleUpload = event => {
const imgElem = this.imgRef.current;
const file = event.target.files[0];
if (file && file.type.startsWith('image/')) {
imgElem.file = file;
const form = new FormData();
form.append('files', file);
fetch('http://68.183.141.111:1337/upload', {
method: 'POST',
headers: {
Accept: 'application/json',
Authorization:
'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YzBkOGJmZGMzNTQwZTAxZmJlNWI3ZTUiLCJpYXQiOjE1NDQ2MzU1NjUsImV4cCI6MTU0NzIyNzU2NX0.17qh3ToPCdNS2qa9CNnjw7PUeMEyX7_3NxuR0xrhVP0',
'Content-Type': 'multipart/form-data'
},
body: form
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment