Open goalbased opened 4 years ago
Any updates on this?
I found I can use uri for form data, so I don't need rn-fetch-blob
to convert my file now, there is my sample code
const formData = new FormData();
formData.append('file', {
uri: this.state.imgUri,
name: `${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}.jpg`,
type: 'image/jpg',
});
You can close this issue
I found I can use uri for form data, so I don't need
rn-fetch-blob
to convert my file now, there is my sample codeconst formData = new FormData(); formData.append('file', { uri: this.state.imgUri, name: `${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}.jpg`, type: 'image/jpg', });
Hey, can you tell me how do you include your formData within the upload method using RNFetchBlob.fetch ?
I found I can use uri for form data, so I don't need
rn-fetch-blob
to convert my file now, there is my sample codeconst formData = new FormData(); formData.append('file', { uri: this.state.imgUri, name: `${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}.jpg`, type: 'image/jpg', });
Hey, can you tell me how do you include your formData within the upload method using RNFetchBlob.fetch ?
Now, I didn't use RNFetchBlob.fetch to upload. I use fetch and below is real word code
onSave = async () => {
this.setState({status: 'camera', imgUri: ''});
const formData = new FormData();
formData.append('file', {
uri: this.state.imgUri,
name: `${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}.jpg`,
type: 'image/jpg',
});
formData.append('projectId', 16);
formData.append('sourceType', 2);
formData.append('filePath', 'photo');
const response = await fetch(
'http://ap-southeast-1.compute.amazonaws.com/api/file/uploadFile',
{
headers: {
Authorization: `Bearer ${global.token}`,
},
method: 'POST',
body: formData,
},
);
};
I found I can use uri for form data, so I don't need
rn-fetch-blob
to convert my file now, there is my sample codeconst formData = new FormData(); formData.append('file', { uri: this.state.imgUri, name: `${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}.jpg`, type: 'image/jpg', });
Hey, can you tell me how do you include your formData within the upload method using RNFetchBlob.fetch ?
Now, I didn't use RNFetchBlob.fetch to upload. I use fetch and below is real word code
onSave = async () => { this.setState({status: 'camera', imgUri: ''}); const formData = new FormData(); formData.append('file', { uri: this.state.imgUri, name: `${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}.jpg`, type: 'image/jpg', }); formData.append('projectId', 16); formData.append('sourceType', 2); formData.append('filePath', 'photo'); const response = await fetch( 'http://ap-southeast-1.compute.amazonaws.com/api/file/uploadFile', { headers: { Authorization: `Bearer ${global.token}`, }, method: 'POST', body: formData, }, ); };
But how to upload binary image using fetch? And dont use rn-fetch-blob
my form data will look like this
but after read the document I can't find how to customize form data or how to read image to binary from uri? do I miss something?