我想从 react-native 上传一张图片到 PHP Symfony 服务器。我用 ImagePicker.showImagePicker 选择图片并用 RNFetchBlob.fetch 发送它,但在 Symfony 中该文件似乎是空的。$file->getMimeType() 返回“文件不存在或不可读”并且文件的内容类型是八位字节流。它应该是图像/JPEG。
任何想法 ?感谢帮助 :)
PHP代码:
private function uploadFile(Request $request, $actualFilename = null)
{
$file = $request->files->get('userfile');
var_dump($file->getMimeType());
}
反应本机代码:
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);
});
});
});