【问题标题】:React Native CameraRoll.getPhotos return the "uri" cannot upload in Web APIReact Native CameraRoll.getPhotos 返回“uri”无法在 Web API 中上传
【发布时间】:2018-11-04 13:24:03
【问题描述】:

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

当我使用 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

谁能帮帮我?非常感谢!

【问题讨论】:

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


    【解决方案1】:

    哦!我的错!

    postData.append('文件', 图像); //追加文件必须是一个一个

    所以改成这个,会很好用的!

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-12
      • 1970-01-01
      • 2022-01-24
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      相关资源
      最近更新 更多