umijs / umi-request

A request tool based on fetch.
2.21k stars 336 forks source link

POST request with base64 image #314

Closed lakarpusky closed 1 year ago

lakarpusky commented 1 year ago

Making a POST call with the following payload structure example as data:

data: {
  adjunto: {
      "attachments": [
          {
              "fileName": "filename.jpg",
              "content": "baks435aSDKFSJLDLFKSODKFSDLFMFM NNK8D67F6D7FD,FKSDIFUSDIFS...."
          }
      ]
  }
}

image


The call payload in the developer tools:

image

Printing the body inside the interceptor you can see that inside the encoded data the array content is missing, but when doing the JSON encoding manually, there is no data loss.

body: "{\"keyname\":{\"attachments\":[]}}"

It's possible to mutate the request body in pre-request or something?

Still haven't found a way to make it work. I think it may be a bug because it only happens with this payload object, but it's a must for me.

Any help or guidance will be appreciated.

lakarpusky commented 1 year ago

I figure it out, it happens that the attachments key in that payload, somehow I think it's conflicting with some internal processing, changing the key name to something else solved the issue. 👍