React Native CameraRoll.getPhotos возвращает «uri» не может загрузить в веб-API - PullRequest
0 голосов
/ 25 мая 2018

CameraRoll.getPhotos (fetchParams) .then ((data) => this._appendImages (data), (e) => console.log (e));

enter image description here

когда я использую FormData

const images = messages.map(k => {
    return {
        uri: k.image,   //`file:///${k.image}`,
        name: k.filename,
        type: mime.lookup(k.filename),
    }
})

console.log(images)

postData = new FormData();
postData.append('file', images);
postData.append('userid', this.user._id);
postData.append('time', moment().format('YYYY-M-D H:mm:ss'));
postData.append('group', this.groupID);

axios.post(WebAPI.url.chat.postImage,
    postData,
    {
        headers: {
            access_token: this.user.access_token,
            'Content-Type': 'multipart/form-data',
        },
    }
).then(response => {
    console.log(response.data)
}).catch(error => {
    console.log(error)
})

C # может получить Request.Form, но не может получить Request.Files

enter image description here

кто может мне помочь?большое спасибо!

1 Ответ

0 голосов
/ 25 мая 2018

ой!моя ошибка!

postData.append ('файл', изображения); // добавляемый файл должен быть один за другим

, поэтому измените его, он будет работать хорошо!

messages.forEach(k => {
    postData.append('file', {
        uri: k.image,
        name: k.filename,
        type: mime.lookup(k.filename),
    });
})
...