4

In pseudo-whish-language this is what I try to achieve in IntelliJ integrated http client:

POST {{basepath}}/upload
Content-Type: application/json

{
  "content": "{% btoa(await fetch('my-file.dat')) %}"
}

Normally, one would use the following to upload a file raw or as part of a multipart request:

< my-file.dat

But in my case, the binary file has to be encapsulated in a json and encoded using base64. I tried putting the file into a variable, but I can't find a way to run a script (for setting the variable) before the request is sent and also it doesn't seem possible to use script directly as part of the request. And I'm also not sure if I'm able to access external files from the script.

I cannot send it as multipart as proposed in Add file to multipart form request in IntelliJ HTTP Client because my server doesn't accept non-json requests.

Do I have any other options or is this a missing feature of this http client?

Daniel Alder
  • 5,031
  • 2
  • 45
  • 55

1 Answers1

1

I did some tricks to achieve something similar.

{
  "dev": {
    "png_image_base64": "--your format data in bae64--"
   }
}
  • Then, I added this as a reference in my HTTP request.
### ADD FILE TO TRACKING
POST http://localhost/files
Content-Type: application/json
Authorization: Bearer {{personal_access_token}}

{
  "file": "{{png_image_base64}}"
}
  • Finally, run the request with the dev environment.

run HTTP request with environment variables

You could create many vars with different files of content: pdf_base64, png_bas464, etc. depending on your necessities. The "bad thing" is that you need to parse manually each of these files, but only once; after that, you could use it on a json and perform many tests.

Pang
  • 9,564
  • 146
  • 81
  • 122
hizmarck
  • 686
  • 9
  • 19