以下のコードを使用して画像をimgur.comにアップロードすると、http400エラーコードが返されます。私の開発者キーは正しく、最大70kbのサイズのさまざまな画像形式を試しました。http://api.imgur.com/examplesにあるc#のコード例も試しましたが、http400も表示されます。何が問題なのでしょうか。
public XDocument Upload(string imageAsBase64String)
{
XDocument result = null;
using (var webClient = new WebClient())
{
var values = new NameValueCollection
{
{ "key", key },
{ "image", imageAsBase64String },
{ "type", "base64" },
};
byte[] response = webClient.UploadValues("http://api.imgur.com/2/upload.xml", "POST", values);
result = XDocument.Load(new MemoryStream(response));
}
return result;
}
編集:これはASP.NET MVCアプリケーションであり、呼び出し元のコントローラーのアクションは次のとおりです。
[HttpPost]
public ActionResult UploadImage(HttpPostedFileBase uploadFile)
{
if (uploadFile.ContentLength > 0)
{
var imgService = new ImgUrImageService();
byte[] fileBytes = new byte[uploadFile.InputStream.Length];
Int64 byteCount = uploadFile.InputStream.Read(fileBytes, 0, (int)uploadFile.InputStream.Length);
uploadFile.InputStream.Close();
string fileContent = Convert.ToBase64String(fileBytes, 0, fileBytes.Length);
var response = imgService.Upload(fileContent);
}
return View();
}