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?
I did some tricks to achieve something similar.
{
"dev": {
"png_image_base64": "--your format data in bae64--"
}
}
### ADD FILE TO TRACKING
POST http://localhost/files
Content-Type: application/json
Authorization: Bearer {{personal_access_token}}
{
"file": "{{png_image_base64}}"
}
dev environment.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With