You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
I'm using such method to upload image via your XML API
public static void UploadImage(HttpPostedFileBase image)
{
var httpWReq =
(HttpWebRequest)WebRequest.Create("http://www.imageshack.us/upload_api.php");
httpWReq.Method = "POST";
httpWReq.ContentType = "multipart/form-data";
httpWReq.KeepAlive = true;
var stream = httpWReq.GetRequestStream();
var encoding = new UTF8Encoding();
var postData = "key=/*my key*/";
postData += "&fileupload=";
byte[] data = encoding.GetBytes(postData);
stream.Write(data, 0, data.Length);
var buffer = new byte[4096];
int bytesread;
while ((bytesread = image.InputStream.Read(buffer, 0, buffer.Length)) != 0)
{
stream.Write(buffer, 0, bytesread);
}
stream.Close();
var response = (HttpWebResponse)httpWReq.GetResponse();
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
but it gives me error "you must provide valid secret key". The problem is that
key is 100% valid. And when I change to
httpWReq.ContentType = "application/x-www-form-urlencoded";
there is no longer error with key, but there is error "no file or empty file
was uploaded".
Here's some sample code, how I use this method
[HttpPost]
public ActionResult SomeAction (SomeViewModel model)
{
//I take image uploaded by user and store it into imageshack
UploadeImage(model.Image);
RedirectToAction("Index");
}
So the question is: Are there any mistakes in this code or is there any more
descent approach to post image via this API?
Thanks in advance!
Original issue reported on code.google.com by [email protected] on 6 Jan 2014 at 4:24
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
[email protected]
on 6 Jan 2014 at 4:24The text was updated successfully, but these errors were encountered: