【发布时间】:2018-12-14 15:23:33
【问题描述】:
早安,
我正在尝试将 javascript blob 图像发送到我在 ASP.NET Core 中的控制器方法,但它没有发送到我的控制器。
我的画布上有一张图片,它是 dataUri 以便能够将其转换为 javascript blob,我正在使用以下代码:
dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
// create a view into the buffer
var ia = new Uint8Array(ab);
// set the bytes of the buffer to the correct values
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
// write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ab], { type: mimeString });
return blob;
}
// Then in my save method here are my javascript codes:
const fileImage = this.dataURItoBlob(myDataUriImage);
axios.post(`Info/Create`, fileImage , {
headers: {
"Content-Type": "multipart/form-data"
}
})
这是我的简单 ASP.NET Core 控制器方法
public async Task<IActionResult> Create([FromBody]IFormFile fileImage)
{
...
}
有什么帮助吗?
【问题讨论】:
标签: javascript c# asp.net-core asp.net-core-2.0 axios