- Published on
React Native Blob上传
- Authors

- Name
- RE
记录下React Native中上传Blob的坑。
- 需要设置
Content-Type为multipart/form-data
const upload = async (formData) => {
const response = await axios.post('http://localhost:3000/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
};
- 需要给出文件路径
const image = 'file://path/to/image.png';
const file = {
uri:
Platform.OS === 'ios'
? image.replace('file://', '')
: image,
name: `photo.${fileType}`,
type: `image/${fileType}`,
};
不知道为什么,直接传Blob并不能上传成功