【发布时间】:2015-01-19 01:26:46
【问题描述】:
我的一个朋友正在尝试使用 chevereto API 将 Windows 窗体应用程序上的图像上传到 chevereto 网站并尝试取回链接(来自网站的响应),但它并没有真正起作用...
API:Chevereto API
更新:添加代码
static class Upload
{
string apiKey = "DEFAULT_API_KEY";
public string UploadImage(Image image)
{
WebClient webClient = new WebClient();
webClient.Headers.Add("key", apiKey);
webClient.Headers.Add("format", "txt");
System.Collections.Specialized.NameValueCollection Keys =
new System.Collections.Specialized.NameValueCollection();
try
{
string ht = "http://";
Keys.Add("image", ImageToBase64(image, ImageFormat.Bmp));
byte[] responseArray = webClient.UploadValues(ht + "mysite.com/api/1/upload/", Keys);
string result = Encoding.ASCII.GetString(responseArray);
return result;
}
catch (Exception e)
{
InternalConsole.LogError("Cannot upload image, error on next line: ");
InternalConsole.Log(e.Message);
return "none";
}
}
public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
}
谁能告诉我它是怎么做的?
提前致谢。
【问题讨论】:
-
可以请你的朋友贴出不起作用的代码吗?
-
已添加代码。感谢您的回复。
标签: c# post image-uploading