问题
I try to send my base64 code to my webservice :
this is my base64 :
I send like this :
let collection= {};
collection.base64 = this.state.data;
fetch('url', {
method: 'POST',
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json', // <-- Specifying the Content-Type
}),
body: JSON.stringify({'JsonWithImage': collection.base64 }), // data can be `string` or {object}!
})
However, as you see it gives error message which is in image. I think because of size of image but I am not sure. Any idea about this ?
回答1:
Via this post there is a javascript function window.btoa() which encodes data to Base64 string which may work for you.
let collection= {};
collection.base64 = this.state.data;
fetch('url', {
method: 'POST',
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json', // <-- Specifying the Content-Type
}),
body: JSON.stringify({'JsonWithImage': window.btoa(collection.base64) }), // data can be `string` or {object}!
})
来源:https://stackoverflow.com/questions/56991655/how-to-send-base64-code-to-webservice-webservice