Use curl to send binary file through POST with content-type multipart/form-data;

15,655

I think the --form option should do what you need:

curl --form "picture[uploaded_data][email protected];type=image/jpeg" http://www.example.com/example/
Share:
15,655

Related videos on Youtube

Martin Čapka
Author by

Martin Čapka

Updated on September 18, 2022

Comments

  • Martin Čapka
    Martin Čapka over 1 year

    A post request is made to:

    http://www.example.com/example/
    

    and the post data is as follows:

    ------WebKitFormBoundaryB8NNdk2kNdndnnn
    Content-Disposition: form-data; name="picture[uploaded_data]"; filename="picture.jpg"
    Content-Type: image/jpeg
    
    binarydatagoeshere
    ------WebKitFormBoundaryB8NNdk2kNdndnnn--
    

    So my question is, how can i use curl to do this exact same thing with the binary data of picture.jpg? I know of --data-binary @myfile.bin, but this is completely different and in this case the string after Boundary e.g B8NNdk2kNdndnnn in this case needs to be valid for the request to go through. So how do i do all this using curl?