hurl icon indicating copy to clipboard operation
hurl copied to clipboard

base64 of file as a JSON input

Open glb-cblin opened this issue 1 year ago • 4 comments

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 ...

glb-cblin avatar Dec 18 '23 14:12 glb-cblin

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

jcamiel avatar Dec 18 '23 20:12 jcamiel

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 avatar Dec 19 '23 07:12 glb-cblin

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

glb-cblin avatar Jun 27 '24 06:06 glb-cblin

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

jcamiel avatar Jun 27 '24 08:06 jcamiel