|
Posted by Gernot Frisch on 01/09/07 08:31
> 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
);
Navigation:
[Reply to this message]
|