我需要将我的react本机签名垫输出作为图像上传到服务器中。
//this.state.base64 is signaturepad output
let blob = new Blob([this.state.base64], {type: 'image/png'});
alert(blob.size);
var fd = new FormData()
fd.append('file',blob,"Sign.png")
let url="http://xxxxxx/xxxx/xxx/";
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data'
},
body: fd
}).then(function (response) {
alert("dfdfdfdfd")
});使用我所获得的上述代码
“多部分身体必须至少有一部分”
错误请任何人帮我解决这个问题
谢谢
发布于 2018-04-18 15:09:08
我认为这样生成blob可能会出现问题,因为Blob(blobParts\[, options\])支持的blobParts类型如下
ArrayofArrayBuffer、ArrayBufferView、Blob、DOMString对象或任何这类对象的组合,这些对象将放在Blob中。DOMStrings被编码为UTF-8。
因此,将base64转换为blob的一个简单方法是使用fetch api。
let base64Url = // Your Base 64 URL
fetch(base64Url)
.then(res => res.blob())
.then(blob => //Use the blob here)然后,您可以按照自己的意愿执行其余的操作。
https://stackoverflow.com/questions/49894508
复制相似问题