Android multer,react本机图像选择器图像上载无法在iOS上运行
我有很大的麻烦上传图像通过获取和反应本机图像采摘到multer和express js后端 下面是我的react本机代码Android multer,react本机图像选择器图像上载无法在iOS上运行,android,ios,fetch,multer,react-native-image-picker,Android,Ios,Fetch,Multer,React Native Image Picker,我有很大的麻烦上传图像通过获取和反应本机图像采摘到multer和express js后端 下面是我的react本机代码 try { const data = new FormData(); data.append('image', { name: photo.fileName, type: photo.type, uri: Platform.OS === 'android' ? photo.uri : photo.uri.replace('file:
try {
const data = new FormData();
data.append('image', {
name: photo.fileName,
type: photo.type,
uri:
Platform.OS === 'android' ? photo.uri : photo.uri.replace('file://', ''),
});
data.append('id', id)
fetch(`${API}save-image`, {
method: 'POST',
body: data,
})
.then(response => response.json())
.then(response => {
console.log('upload succes', response);
})
.catch(error => {
console.log('upload error', error);
});
} catch (error) {
console.log(error);
if (error.response !== undefined) {
message = error.response.data.message;
} else {
message = error;
}
return Promise.reject(message);
}
image
变量是我们从包含图像数据和uri以及其他所需项的react本机图像选择器库中获取的响应对象
在后端,我尝试登录multer配置的req.files对象
const Storage = multer.diskStorage({
destination(req, file, callback) {
callback(null, path.join(__dirname, '../uploads/'));
},
filename(req, file, callback) {
callback(null, new Date().toISOString() + '_' + file.originalname);
},
});
const upload = multer({
storage: Storage,
limits: { fieldSize: 25 * 1024 * 1024 },
});
router.post(
'/save-image',
upload.array('image', 3),
controller.saveImage
);
在控制器中,我只需console.log(req.files)
,然后返回成功消息
我可以在android emulator上看到控制台日志,但在iOS emulator上看不到
事实上,图像似乎没有被发送到后端。但是后端没有错误,并且在iOS中不会记录
这真令人沮丧
有人能帮忙吗?下面的react native和flipper版本出现问题,导致文件上载的网络请求失败,请尝试手动更新flipper版本。在您的
播客文件中
:
versions['Flipper'] ||= '~> 0.51.0'
谢谢,我坚持了很多天,在更新flipper版本后得到了修复