modelbinder IsMultiPartContent always returning false. How to upload file with react

让人想犯罪 __ 提交于 2019-12-07 20:47:25

I do not know React, but it seems your request is no multipart/form-data request.

You use ContentType correctly, but your data is JSON as I understand...

You need to send FormData object.

Something like this:

const formData = new FormData()
formData.append("model", {"TenantId": this.state.TenantId, "TenantUrl": this.state.TenantUrl, "TenantPassword": this.state.TenantPassword });
let files = event.target.files;
for (let i = 0; i < files.length; i++) {
    formData.append('content', files[i], files[i].name);
}

const options = {
    method: 'put',
    data: formData,
    config: {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    }
};

In any case all necessary information you can find in documentation link here.

Please review this example of sending multipart/form-data on jQuery.

And this example on React.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!