alphapapa / plz.el

An HTTP library for Emacs
GNU General Public License v3.0
202 stars 11 forks source link

Allow additional arguments to curl? #4

Open titaniumbones opened 2 years ago

titaniumbones commented 2 years ago

I'd like to use plz to upload files to an authorized endpoint. That endpoint requires the file and various dynamically-assigned parameters to be passed as multipart form data. In curl this is achieved with command-line arguments like:

curl '<upload_url>' \
     -F 'key=/users/1234/files/profile_pic.jpg' \
     <any other parameters specified in the upload_params response>
     -F 'file=@my_local_file.jpg'

How would you feel about allowing an additional parameter :additional-cli-args (or something) that gets added to curl-command-line-args, or maybe just replaces plz-curl-default-args? This would allow me to use plz for such requests. What do you think?

alphapapa commented 2 years ago

Hi Matt,

We could add such a variable if necessary, but I think you can just bind plz-curl-default-args to whatever value you need before calling plz to accomplish the same thing. AFAIK it should work, unless there's some kind of conflict in argument order. Please try it and let me know if it works.

alphapapa commented 1 year ago

By the way, for the use case you present, ideally there would be no need for the user to specify additional arguments for curl--rather, it should all be doable with plz's own API. So if you'd like, we could talk further about how to implement that according to your needs.

lorniu commented 2 months ago

Same requirement.

I tried to bind like this:

(let ((plz-curl-default-args
       (append plz-curl-default-args
               (list
                "--form" "aaa=3"
                "--form" "f=@~/aaa.jpg"))))
  (plz 'post "https://httpbin.org/post"))

But error Failed to initialize raised.

Maybe variable like plz-curl-default-config-args can be added to pass extra config args.

alphapapa commented 2 months ago

But error Failed to initialize raised.

Probably because you passed a path containing ~, which Curl probably doesn't expand itself; remember that a shell is not involved here, so ~ won't get expanded.

lorniu commented 2 months ago

Probably because you passed a path containing ~

Same error when absolute path like /Users/xxx/aaa.jpg is used.

alphapapa commented 2 months ago

Probably because you passed a path containing ~

Same error when absolute path like /Users/xxx/aaa.jpg is used.

Then it's probably due to argument order.

As I said on #62, if you need multipart/form-data support, please open an issue about it. And if you want to make a PR to support that, feel free.