React Native CameraRoll.getPhotos返回“uri”无法上传到Web API

时间:2018-05-25 07:55:08

标签: c# react-native asp.net-web-api image-upload camera-roll

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 :(得分:0)

哦!我的错!

postData.append('file',images); //追加文件必须一个接一个

所以改变这一点,会很好用!

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