Orange-OpenSource / hurl

Hurl, run and test HTTP requests with plain text.
https://hurl.dev
Apache License 2.0
12.38k stars 473 forks source link

base64 of file as a JSON input #2258

Open glb-cblin opened 7 months ago

glb-cblin commented 7 months ago

Problem to solve

I'd like to upload the base64 of a file in one of the parameter of the body

# Upload picture
POST {{PUBLIC_URL}}/public-picture-api/my-pictures
Authorization: Bearer {{id_token}}
{
  "file": "//TODO",
  "fileType": "JPEG",
  "title": "{{title}}",
  "tags": ["{{tag}}"] 
}

At the moment, i must put the whole JSON body in a file ...

jcamiel commented 7 months ago

Hi @glb-cblin

Currently, there is no way to inject data in a Hurl file appart from variable.

Like with filter, we're going to introduced generators that will allow this usecase:

# Upload picture
POST {{PUBLIC_URL}}/public-picture-api/my-pictures
Authorization: Bearer {{id_token}}
{
  "file": {{ file "/tmp/foo.bin" base64Encode }},
  "fileType": "JPEG",
  "title": "{{title}}",
  "tags": ["{{tag}}"] 
}

(The syntax is still to be defined). In this file file "foo.bin" is a generatord, followed by a filter base64dec

See also #2145

glb-cblin commented 7 months ago

Hi @jcamiel

I've seen #2145 but I thought it was just for Asserts and Captures

Glad to know it will also be usable in bodies !

glb-cblin commented 4 weeks ago

Hi @jcamiel

As you closed the related issue, I was testing that on my use case

It does not seem to work

when using "file": {{ file "pic.jpg" base64Encode }}, I have an error ^ expecting '}}' for the "

when using "file": {{ file pic.jpg base64Encode }}, I have an error ^^^^ you must set the variable file for the file keyword

Am I doing something wrong ?

hurl 4.3.0 (Windows) libcurl/8.4.0-DEV Schannel zlib/1.3 nghttp2/1.58.0
Features (libcurl):  alt-svc AsynchDNS HSTS HTTP2 IPv6 Largefile libz NTLM SPNEGO SSL SSPI Unicode UnixSockets
Features (built-in): brotli
jcamiel commented 4 weeks ago

Hi @glb-cblin the generators feature is still not implemented, the closed issue was a try to have a meta "issue" for grouping relating issues. We've now switch to grouping related issue with labels beginning with "topic:" for instance, https://github.com/Orange-OpenSource/hurl/labels/topic%3A%20generators

I'll update #2302 with a warning