Re: post image to webhoster - upload file with http




this question might be off topic, but anyway.
I want to upload an image to imageshack in C++. I have a function,
where I can specify a url, post data and header.

Do I need to include the image data (mime boundary thingy) in the
header?

Or uhm.. where do I put the image data when uploading?

Got it working. FYI:

// Make POST data for file upload
String boundary, sHeader, sPostData, sFileContent;


boundary="--UPLOAD--BOUNDARY--123j123498sadfj32--UPLOAD-BOUNDARY--";
sHeader = "Content-Type: multipart/form-data,
boundary="+boundary+"\r\n";

sFileContent.ReadBinary(file_name);


#define ADDVAR(s, n, v) \
s = s + "--"+boundary \
+ "\r\nContent-Disposition: form-data; name=\""\
+ String(n)+ "\"\r\n\r\n"\
+ String(v)+"\r\n";

ADDVAR(sPostData, "MAX_FILE_SIZE", "1048576");
ADDVAR(sPostData, "Submit1", "host it!");


// Post the file
sPostData +=
"--"+boundary+"\r\n"
"Content-Disposition: form-data;"
" name=\"fileupload\";"
" filename=\""+filename+"\"\r\n"
"Content-Transfer-Encoding: binary\r\n"
"Content-Type: application/octet-stream\r\n\r\n"
+ sFileContent + "\r\n";

sPostData += "--"+boundary+"--";

CAmHttpSocket http;

char *s = http.GetPage(
_T("http://mysite/index.php";),
true,
sPostData, sPostData.GetLength(),
sHeader
);


.



Relevant Pages

  • Re: upload file using webbrowser
    ... > Can anyone tell me how can I programmly set the file name and submit ... An ability for the script to upload an arbitrary file ... Automate Internet Explorer to POST Form ... POST data in the correct format. ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • able to upload 28 meg file, yet php.ini limits posts to 10 megs. What is up with that?
    ... Maximum size of POST data that PHP will accept. ... However, I was assuming that the upload should have failed, before the PHP script ever had the chance to resize the file. ... But I've never seen Plesk undermine the importance of the post_max_size setting, nor can I imagine where Plesk might store such a conf setting if it did. ...
    (comp.lang.php)
  • I am able to upload a 28 meg file, yet php.ini limits posts to 10 megs. What is up with that?
    ... Maximum size of POST data that PHP will accept. ... However, I was assuming that the upload should have failed, before the PHP script ever had the chance to resize the file. ... But I've never seen Plesk undermine the importance of the post_max_size setting, nor can I imagine where Plesk might store such a conf setting if it did. ...
    (comp.lang.ruby)
  • RE: [PHP] More info on timeout problem
    ... [PHP] More info on timeout problem ... and nothing I do seems to let me upload anything larger than a 2MB file. ... Sets max size of post data allowed. ... This setting also affects file upload. ...
    (php.general)
  • Re: Post Without Return
    ... open up a socket, ... just add code to send POST data, it is in the header just like a GET, last ... > I have used fsockopenand cURL for posting to remote servers where I> wanted to get a return value, but how do you post to a remote server> programatically where you want to go to the result page on that> server? ...
    (alt.php)