Can't be sure but in my case I had to add a 'name' field to the file. Following other advices, I've end up with something like this:
import axios from 'axios';
import FormData from 'form-data';
function upload (data, images, token) {
const formData = new FormData();
formData.append('data', data);
images.forEach((image, i) => {
formData.append('images', {
...image,
uri: Platform.OS === 'android' ? image.uri : image.uri.replace('file://', ''),
name: `image-${i}`,
type: 'image/jpeg', // it may be necessary in Android.
});
});
const client = axios.create({
baseURL: 'http://localhost:3001',
});
const headers = {
Authorization: `Bearer ${token}`,
'Content-Type': 'multipart/form-data'
}
client.post('/items/save', formData, headers);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…