Search code examples
httpuploadputhttpie

How to upload a file with PUT in HTTPie


I'm searching for the syntax to write a PUT operation that upload a file with HTTPie. Please could you point me to the right syntax ? I could not find a way to do so on the official documentation


Solution

  • To achieve this with httpie, you need to do two things:

    1. Set the HTTP method to PUT, which is trivial: $ http PUT […]
    2. Pass the contents of the file, for which there are various ways:

    Redirected input:

    $ http PUT httpbin.org/put Content-Type:image/png < /images/photo.png
    

    Request data from a filename (automatically sets the Content-Type header):

    $ http PUT httpbin.org/put @/images/photo.png
    

    Form file upload:

    $ http --form PUT httpbin.org/put photo=@/images/photo.png