I want to upload a picture from react-native to PHP Symfony server. I pick the picture with ImagePicker.showImagePicker and send it with RNFetchBlob.fetch, but in Symfony the file seems to be empty. The $file->getMimeType() return "file does not exist or is not readable" and the content type of the file is octet-stream. It Should be image/jpeg.
Any Idea ? Thanks for help :)
PHP code:
private function uploadFile(Request $request, $actualFilename = null)
{
$file = $request->files->get('userfile');
var_dump($file->getMimeType());
}
React-native code :
const options = {
title: 'Select Photo',
takePhotoButtonTitle: "Take photo title",
chooseFromLibraryButtonTitle: "Choose a photo",
quality: 1
};
ImagePicker.showImagePicker(options, response => {
deviceStorage.getItem('jwt').then(jwt => {
const endpoint = 'someEndpoint'
RNFetchBlob.fetch('POST', endpoint, {
Authorization : "Bearer " + jwt,
otherHeader : "foo",
'Content-Type' : 'multipart/form-data',
}, [
{ name : 'userfile', filename : 'image.jpg', type:'image/jpeg', data: response.data}
]).then((resp) => {
console.log(resp);
}).catch((err) => {
console.log(err);
});
});
});