아래 코드를 사용하여 imgur.com으로 이미지를 업로드하면 http 400 오류 코드가 반환됩니다. 내 개발자 키가 정확하고 크기가 70kb까지 다른 이미지 형식을 시도했습니다. http://api.imgur.com/examples에 주어진 C#의 코드 예제도 시도했지만 http 400도 제공합니다. 무슨 문제 일 수 있습니까?imgur에 이미지 업로드하기 C#
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;
}
편집 :
[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();
}
혹시이 기능을 사용하셨습니까? – theChrisKent
아니요, 여전히 동일합니다. 그것은 제가 집에서 작업하고있는 부수적 인 프로젝트입니다. 다른 이미지 서비스를 살펴볼 것입니다. – rovsen