plz.el icon indicating copy to clipboard operation
plz.el copied to clipboard

Support `multipart/form-data` `POST` requests

Open josephmturner opened this issue 2 years ago • 4 comments
trafficstars

According to this SO post, multipart/form-data POST requests can be accomplished using curl like so:

curl -v -F key1=value1 -F upload=@localfilename URL

josephmturner avatar Feb 23 '23 05:02 josephmturner

#4 shows an example of this also.

alphapapa avatar Jun 30 '23 03:06 alphapapa

Appending things to plz-curl-default-args seems not to work very well. For example, the code below gives curl error 2 (Failed to initialize). The reason seems to be that the @- argument which is also added in this case is incompatible with -F.

(let* ((plz-curl-default-args
        `("-F" "file=@/some/existing/file"
          ,@plz-curl-default-args)))
  (plz 'post "https://httpbin.org/post"))

I think one could come up with a reasonable :body notation for form submissions along the lines of

(form (name "first-part" file "file1.txt" type "text/plain") 
      (name "second-part" body "some <i>text<i> in my form" type "text/html"))

astoff avatar Oct 04 '23 19:10 astoff

Yeah, I didn't mean for users to modify the default args in order to send form data. :)

As for the body: I'll need to take another look at the spec to see how that works. It might be possible to send a form-data part and a non-form-data part, in which case using :body might be inappropriate. But anyway, specifying the form data could probably be done with one or more alists (or even just any map type using the map library).

alphapapa avatar Oct 04 '23 21:10 alphapapa

Yes, I really want to get the form support, especially to upload file without reading to Emacs buffer with some additional text parameters. It would be very helpful if @astoff 's suggestion can be implemented.

cinsk avatar Oct 10 '23 03:10 cinsk