0

I want to upload image manually using a button click and then send it to the WebAPI and get response accordingly.

This is .html page

<script>
    function getdata() {
        var data = new FormData();
        var files = $("#fileUpload").get(0).files;
        var complexobj = {
            filetosend: files[0]
        };
        var obj = { Mydata: complexobj };
        var data2send =  JSON.stringify(obj);
        $.ajax({
            type: "POST",
            url: 'http://localhost:3469/api/values',
            data: data2send,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            processdata: false,
        }).done(function (data) {
            document.getElementById("label").innerHTML = data;
        });

    }
</script>
....
....
....
....
<input id="fileUpload" type="file" />

This is my Mydata.cs class file

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;

namespace CNTKAzureTutorial01
{
    public class Mydata
    {
        public Bitmap filetosend { get; set; }
    }
}

This is my ValuesController.cs file

[SwaggerOperation("Create")]
    [SwaggerResponse(HttpStatusCode.Created)]
    public async Task<HttpResponseMessage> Post([FromBody]Mydata value)
    {
        Bitmap input = value.filetosend;
        string[] output = await EvaluateCustomDNN(input);
        return Request.CreateResponse(HttpStatusCode.OK, output);
    }

I am getting response error 500, I tried debugging it using breakpoints in Visual Studio but still I am not able to debug it. Can you please help me?

0 Answers0