Created
December 12, 2018 17:55
-
-
Save whizkydee/447472cf9d72d1f7d6860ab28b417a62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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