G
Guest
Hi,
I'm programatically posting an image using multipart/form-data. It sends to the server OK, but when I try to view it in the browser, it is still in the base64 string I sent it as: /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUG etc....
I've been through the form I built over and over:
string PostData = "";
PostData += "-----------------------------7d41fb3081216";
PostData += "\r";
PostData += "\n";
PostData += "Content-Disposition: form-data; name=\"userfile\"; filename=" + "\"c:\\temp\\" + "myimg.jpg\";";
PostData += "\r";
PostData += "\n";
PostData += "Content-Type: image/jpeg; name=\"myimg.jpg\";";
PostData += "\r";
PostData += "\n";
PostData +="Content-Transfer-Encoding: binary;";
PostData += "\r";
PostData += "\n";
PostData += "\r";
PostData += "\n";
string image_string = Convert.ToBase64String(documentcontents);
PostData += image_string;
PostData += "\r";
PostData += "\n";
PostData += "-----------------------------7d41fb3081216--";
This is the how i'm reading the image in:
string strdocPath;
strdocPath = "c:\\temp\\" + "myimg.jpg";
FileStream objfilestream = new FileStream(strdocPath,FileMode.Open,FileAccess.Read);
int len = (int)objfilestream.Length;
Byte[] documentcontents = new Byte[len];
objfilestream.Read(documentcontents,0,len);
objfilestream.Close();
I've tried pretty much every order of mimes, but still the image isn't sent properly. Does anyone have any experience of this or what could be causing the base64 string to show like that?
Thanks
I'm programatically posting an image using multipart/form-data. It sends to the server OK, but when I try to view it in the browser, it is still in the base64 string I sent it as: /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUG etc....
I've been through the form I built over and over:
string PostData = "";
PostData += "-----------------------------7d41fb3081216";
PostData += "\r";
PostData += "\n";
PostData += "Content-Disposition: form-data; name=\"userfile\"; filename=" + "\"c:\\temp\\" + "myimg.jpg\";";
PostData += "\r";
PostData += "\n";
PostData += "Content-Type: image/jpeg; name=\"myimg.jpg\";";
PostData += "\r";
PostData += "\n";
PostData +="Content-Transfer-Encoding: binary;";
PostData += "\r";
PostData += "\n";
PostData += "\r";
PostData += "\n";
string image_string = Convert.ToBase64String(documentcontents);
PostData += image_string;
PostData += "\r";
PostData += "\n";
PostData += "-----------------------------7d41fb3081216--";
This is the how i'm reading the image in:
string strdocPath;
strdocPath = "c:\\temp\\" + "myimg.jpg";
FileStream objfilestream = new FileStream(strdocPath,FileMode.Open,FileAccess.Read);
int len = (int)objfilestream.Length;
Byte[] documentcontents = new Byte[len];
objfilestream.Read(documentcontents,0,len);
objfilestream.Close();
I've tried pretty much every order of mimes, but still the image isn't sent properly. Does anyone have any experience of this or what could be causing the base64 string to show like that?
Thanks