Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

This is a sample script in to POST multipart. You need to adapt it a bit :

#!/usr/bin/env perl

use strict; use warnings;
use WWW::Mechanize;

my $m = WWW::Mechanize->new(
    autocheck => 1,
    agent_alias => 'Mozilla',
    cookie_jar => {},
    ssl_opts => {verify_hostname => 0},
    quiet => 0,
);
$m->get("http://domain.tld");                                                   

$m->post('https://domain.tld/send',
    Content_Type => "form-data",
    Content => [
        'picture[uploaded_data]' => 'foobar',
        file => [ '/path/to/image', 'image_name', 'Content-Type' => 'image/jpeg' ]
    ]
);

print $m->content;

Check http://search.cpan.org/~gaas/HTTP-Message-6.06/lib/HTTP/Request/Common.pm

share|improve this answer

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|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.