How to send Base64 code to webservice webservice?

时光毁灭记忆、已成空白 提交于 2019-12-11 17:20:08

问题


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

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