I am looking to use Deviantsart's public API in order to host some images for a project I am working on.
The issue I am having is I am not getting the JSON result back with the URL but instead getting the entire webpage.
their instructions are relatively simple
Upload using our public REST API: POST http://deviantsart.com yourimage.jpg
Then returns a JSON-Result with the URL:
{ "url" : "urltoimage" }
Here is my code.
WebAPI
[HttpPost]
public async Task<HttpResponseMessage> UploadGliderData()
{
if (!Request.Content.IsMimeMultipartContent())
{
this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
var httpPostedFile = HttpContext.Current.Request.Files["file"];
using (var client = new HttpClient())
{
using (var content =
new MultipartFormDataContent())
{
var image = new Bitmap(httpPostedFile.InputStream);
var stream = new MemoryStream();
image.Save(stream, ImageFormat.Jpeg);
var imgContent = new StreamContent(stream);
imgContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg");
content.Add(imgContent);
using (
var message =
await client.PostAsync("http://deviantsart.com", content))
{
var input = await message.Content.ReadAsStringAsync();
return this.Request.CreateResponse(HttpStatusCode.OK, input);
}
}
}
}
AngularJS Controller
function upload(files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
Upload.upload({
url: '/api/SGWebAPI/UploadGliderData',
method: 'POST',
data: $scope.glider,
file: file
})
.success(function (data, status, headers, config) {
debugger;
console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
}).error(function (data, status, headers, config) {
debugger;
console.log('error status: ' + status);
});
}
}
Result
The value for input can be found Here
Thank you in advance