I am trying to upload an image to imagehost http://uploads.im/.
According to its very short API, http://uploads.im/apidocsthis is the way to do this:
http://uploads.im/api?upload=http://www.google.com/images/srpr/nav_logo66.png
Please note that in this example it downloads an image from the Internet, and Im trying to download a file from my computer.
the code:
public ActionResult SaveUploadedFile()
{
Image postData = img;
byte[] byteArray = imageToByteArray(postData);
WebRequest wrq = WebRequest.Create("http://uploads.im/api?upload=");
wrq.Method = ("POST");
using (WebResponse wrs = wrq.GetResponse())
using (Stream stream = wrs.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
string json = reader.ReadToEnd();
tempJson = json;
}
}
Please look! Thank!
EDIT, new code:
string filepath = @"c:\Users\xxxx\Desktop\Bilder\images\blank.gif";
using (WebClient client = new WebClient())
{
client.UploadFile("http://uploads.im/api?upload", filepath);
}
I get an error :: Closed connection closed
EDIT with try catch:
string filepath = @"c:\Users\xxxx\Desktop\sack.png";
using (WebClient client = new WebClient())
{
try
{
client.UploadFile("http://uploads.im/api?upload", filepath);
}
catch (Exception e)
{
throw new ApplicationException(e);
}
}
source
share