Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support curl embed content of a file as text field in multipart/form-data request #3730

Open
meixger opened this issue Feb 10, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@meixger
Copy link

meixger commented Feb 10, 2025

Problem to solve

I want to send multipart/form-data request and set the contents for a text field from a file.
Don't attach it as a file upload by adding a filename= to the Content-Disposition.

Instead of

--delimiter
Content-Disposition: form-data; name="field1"; filename="value1.txt"

value1
--delimiter--

i want

--delimiter
Content-Disposition: form-data; name="field1"

value1
--delimiter--

Proposal

Use embedfile instead of file:

POST https://example.org/api
[MultipartFormData]
field1: embedfile,value1.txt

Additional context and resources

Curl`s documentation https://curl.se/docs/manpage.html#-F

To just get the content part from a file, prefix the filename with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.

@meixger meixger added the enhancement New feature or request label Feb 10, 2025
@jcamiel
Copy link
Collaborator

jcamiel commented Feb 10, 2025

Hi @meixger

Do I understand correctly your use case if I emulate it by injecting a variable:

$ value1=`cat file.txt` 
$ hurl --variable value1="$value1" form.hurl

with form.hurl being:

POST http://localhost:8000
[MultipartFormData]
field1: {{value1}}

Instead of injecting the value of file.txt, you want to be able to do:

POST http://localhost:8000
[MultipartFormData]
field1: {{ getFile "file.txt" }}

@meixger
Copy link
Author

meixger commented Feb 10, 2025

Hi @jcamiel

Do I understand correctly your use case if I emulate it by injecting a variable:

Yes.

I assume the proposed function getFile would load the content of file.txt and insert it as the value of field1.

@jcamiel
Copy link
Collaborator

jcamiel commented Feb 10, 2025

Yes exactly, we have "functions" today https://hurl.dev/docs/templates.html#functions, we can imagine having a function getFile that returns the content of a file.

Some things to not forget (for the implementation)

  • content of the file: binary vs text
  • security: restrict the ablity to upload any local file i.e.: forbid {{ getFile "/etc/passwd" }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants