Sending byte array to API












0















I am converting web application to mobile app. We were using AjaxAsyncFileUpload in web application to save a document to the server, where AjaxAsyncFileUpload use to do the work for me. This was the code



Dim fileData As Byte() =new Byte(AjaxAsyncFileUpload.FileContent.Length-1){}
AjaxAsyncFileUpload.FileContent.Read(fileData, 0, fileData.Length)

InvestmentDeclare.DocSize = AjaxAsyncFileUpload.FileContent.Length
InvestmentDeclare.DocFileName = AjaxAsyncFileUpload.FileName
InvestmentDeclare.DocFileType = AjaxAsyncFileUpload.PostedFile.ContentType
InvestmentDeclare.Document = fileData


And then simply save this to my database.



Now while Converting this to mobile app (I am also using c# for mobile app), I am not able to pass the byte array. I am using fiddler for testing.
I have attached an image of how I'm passing it through fiddler. In my API POST method I'm getting a null value to my document variable while I'm able to get rest of my values properly.



What could be the issue? Am I not passing the byte in proper Json format?



In API:



public class AddInvestmentDeclare
{
public int EmployeeId { get; set; }
public int YearId { get; set; }
public int InvestmentId { get; set; }
public List<EmpDocument> EmpDocuments { get; set; }
}

public class EmpDocument
{
public byte Document { get; set; }
public string DocumentFileName { get; set; }
public long DocumentSize { get; set; }
public string DocumentType { get; set; }
}

public HttpResponseMessage Post(int YearId, [FromBody]List<AddInvestmentDeclare> InvestmentDeclared)
{


When I check my InvestDeclared list on run time I see that document variable is not filled and it is showing null. I have attached an image of that as well.










share|improve this question

























  • Anyone who can help me with this please?

    – Tausif Khan
    Oct 15 '18 at 5:40











  • What is the application that is actually calling the post method? Show that code please. Fiddler is good for testing and to properly upload a file use stackoverflow.com/a/51622705/1260204. To read that file in, if it is passed correctly, see stackoverflow.com/questions/10320232/how-to-accept-a-file-post.

    – Igor
    Nov 14 '18 at 10:37











  • Have you tried sending the byte array as string? I've found some example that I used for testing and the JSON that I'm using looks like this: { "ID":46, "Content":"JVBERi0xLjQNCjEgMCBvYm......" } Also, try converting it with this stackoverflow.com/a/11654825/9233618

    – Matt
    Nov 14 '18 at 13:02











  • Also, why don't you set up API method in a way that it accepts just one object containing all data, instead of each parameter individually?

    – Matt
    Nov 15 '18 at 12:16











  • @Matt : Yes of course i can do that.

    – Tausif Khan
    Nov 16 '18 at 6:12
















0















I am converting web application to mobile app. We were using AjaxAsyncFileUpload in web application to save a document to the server, where AjaxAsyncFileUpload use to do the work for me. This was the code



Dim fileData As Byte() =new Byte(AjaxAsyncFileUpload.FileContent.Length-1){}
AjaxAsyncFileUpload.FileContent.Read(fileData, 0, fileData.Length)

InvestmentDeclare.DocSize = AjaxAsyncFileUpload.FileContent.Length
InvestmentDeclare.DocFileName = AjaxAsyncFileUpload.FileName
InvestmentDeclare.DocFileType = AjaxAsyncFileUpload.PostedFile.ContentType
InvestmentDeclare.Document = fileData


And then simply save this to my database.



Now while Converting this to mobile app (I am also using c# for mobile app), I am not able to pass the byte array. I am using fiddler for testing.
I have attached an image of how I'm passing it through fiddler. In my API POST method I'm getting a null value to my document variable while I'm able to get rest of my values properly.



What could be the issue? Am I not passing the byte in proper Json format?



In API:



public class AddInvestmentDeclare
{
public int EmployeeId { get; set; }
public int YearId { get; set; }
public int InvestmentId { get; set; }
public List<EmpDocument> EmpDocuments { get; set; }
}

public class EmpDocument
{
public byte Document { get; set; }
public string DocumentFileName { get; set; }
public long DocumentSize { get; set; }
public string DocumentType { get; set; }
}

public HttpResponseMessage Post(int YearId, [FromBody]List<AddInvestmentDeclare> InvestmentDeclared)
{


When I check my InvestDeclared list on run time I see that document variable is not filled and it is showing null. I have attached an image of that as well.










share|improve this question

























  • Anyone who can help me with this please?

    – Tausif Khan
    Oct 15 '18 at 5:40











  • What is the application that is actually calling the post method? Show that code please. Fiddler is good for testing and to properly upload a file use stackoverflow.com/a/51622705/1260204. To read that file in, if it is passed correctly, see stackoverflow.com/questions/10320232/how-to-accept-a-file-post.

    – Igor
    Nov 14 '18 at 10:37











  • Have you tried sending the byte array as string? I've found some example that I used for testing and the JSON that I'm using looks like this: { "ID":46, "Content":"JVBERi0xLjQNCjEgMCBvYm......" } Also, try converting it with this stackoverflow.com/a/11654825/9233618

    – Matt
    Nov 14 '18 at 13:02











  • Also, why don't you set up API method in a way that it accepts just one object containing all data, instead of each parameter individually?

    – Matt
    Nov 15 '18 at 12:16











  • @Matt : Yes of course i can do that.

    – Tausif Khan
    Nov 16 '18 at 6:12














0












0








0








I am converting web application to mobile app. We were using AjaxAsyncFileUpload in web application to save a document to the server, where AjaxAsyncFileUpload use to do the work for me. This was the code



Dim fileData As Byte() =new Byte(AjaxAsyncFileUpload.FileContent.Length-1){}
AjaxAsyncFileUpload.FileContent.Read(fileData, 0, fileData.Length)

InvestmentDeclare.DocSize = AjaxAsyncFileUpload.FileContent.Length
InvestmentDeclare.DocFileName = AjaxAsyncFileUpload.FileName
InvestmentDeclare.DocFileType = AjaxAsyncFileUpload.PostedFile.ContentType
InvestmentDeclare.Document = fileData


And then simply save this to my database.



Now while Converting this to mobile app (I am also using c# for mobile app), I am not able to pass the byte array. I am using fiddler for testing.
I have attached an image of how I'm passing it through fiddler. In my API POST method I'm getting a null value to my document variable while I'm able to get rest of my values properly.



What could be the issue? Am I not passing the byte in proper Json format?



In API:



public class AddInvestmentDeclare
{
public int EmployeeId { get; set; }
public int YearId { get; set; }
public int InvestmentId { get; set; }
public List<EmpDocument> EmpDocuments { get; set; }
}

public class EmpDocument
{
public byte Document { get; set; }
public string DocumentFileName { get; set; }
public long DocumentSize { get; set; }
public string DocumentType { get; set; }
}

public HttpResponseMessage Post(int YearId, [FromBody]List<AddInvestmentDeclare> InvestmentDeclared)
{


When I check my InvestDeclared list on run time I see that document variable is not filled and it is showing null. I have attached an image of that as well.










share|improve this question
















I am converting web application to mobile app. We were using AjaxAsyncFileUpload in web application to save a document to the server, where AjaxAsyncFileUpload use to do the work for me. This was the code



Dim fileData As Byte() =new Byte(AjaxAsyncFileUpload.FileContent.Length-1){}
AjaxAsyncFileUpload.FileContent.Read(fileData, 0, fileData.Length)

InvestmentDeclare.DocSize = AjaxAsyncFileUpload.FileContent.Length
InvestmentDeclare.DocFileName = AjaxAsyncFileUpload.FileName
InvestmentDeclare.DocFileType = AjaxAsyncFileUpload.PostedFile.ContentType
InvestmentDeclare.Document = fileData


And then simply save this to my database.



Now while Converting this to mobile app (I am also using c# for mobile app), I am not able to pass the byte array. I am using fiddler for testing.
I have attached an image of how I'm passing it through fiddler. In my API POST method I'm getting a null value to my document variable while I'm able to get rest of my values properly.



What could be the issue? Am I not passing the byte in proper Json format?



In API:



public class AddInvestmentDeclare
{
public int EmployeeId { get; set; }
public int YearId { get; set; }
public int InvestmentId { get; set; }
public List<EmpDocument> EmpDocuments { get; set; }
}

public class EmpDocument
{
public byte Document { get; set; }
public string DocumentFileName { get; set; }
public long DocumentSize { get; set; }
public string DocumentType { get; set; }
}

public HttpResponseMessage Post(int YearId, [FromBody]List<AddInvestmentDeclare> InvestmentDeclared)
{


When I check my InvestDeclared list on run time I see that document variable is not filled and it is showing null. I have attached an image of that as well.







asp.net-web-api2 fiddler






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 18:23









Matt

324212




324212










asked Oct 12 '18 at 13:08









Tausif KhanTausif Khan

96




96













  • Anyone who can help me with this please?

    – Tausif Khan
    Oct 15 '18 at 5:40











  • What is the application that is actually calling the post method? Show that code please. Fiddler is good for testing and to properly upload a file use stackoverflow.com/a/51622705/1260204. To read that file in, if it is passed correctly, see stackoverflow.com/questions/10320232/how-to-accept-a-file-post.

    – Igor
    Nov 14 '18 at 10:37











  • Have you tried sending the byte array as string? I've found some example that I used for testing and the JSON that I'm using looks like this: { "ID":46, "Content":"JVBERi0xLjQNCjEgMCBvYm......" } Also, try converting it with this stackoverflow.com/a/11654825/9233618

    – Matt
    Nov 14 '18 at 13:02











  • Also, why don't you set up API method in a way that it accepts just one object containing all data, instead of each parameter individually?

    – Matt
    Nov 15 '18 at 12:16











  • @Matt : Yes of course i can do that.

    – Tausif Khan
    Nov 16 '18 at 6:12



















  • Anyone who can help me with this please?

    – Tausif Khan
    Oct 15 '18 at 5:40











  • What is the application that is actually calling the post method? Show that code please. Fiddler is good for testing and to properly upload a file use stackoverflow.com/a/51622705/1260204. To read that file in, if it is passed correctly, see stackoverflow.com/questions/10320232/how-to-accept-a-file-post.

    – Igor
    Nov 14 '18 at 10:37











  • Have you tried sending the byte array as string? I've found some example that I used for testing and the JSON that I'm using looks like this: { "ID":46, "Content":"JVBERi0xLjQNCjEgMCBvYm......" } Also, try converting it with this stackoverflow.com/a/11654825/9233618

    – Matt
    Nov 14 '18 at 13:02











  • Also, why don't you set up API method in a way that it accepts just one object containing all data, instead of each parameter individually?

    – Matt
    Nov 15 '18 at 12:16











  • @Matt : Yes of course i can do that.

    – Tausif Khan
    Nov 16 '18 at 6:12

















Anyone who can help me with this please?

– Tausif Khan
Oct 15 '18 at 5:40





Anyone who can help me with this please?

– Tausif Khan
Oct 15 '18 at 5:40













What is the application that is actually calling the post method? Show that code please. Fiddler is good for testing and to properly upload a file use stackoverflow.com/a/51622705/1260204. To read that file in, if it is passed correctly, see stackoverflow.com/questions/10320232/how-to-accept-a-file-post.

– Igor
Nov 14 '18 at 10:37





What is the application that is actually calling the post method? Show that code please. Fiddler is good for testing and to properly upload a file use stackoverflow.com/a/51622705/1260204. To read that file in, if it is passed correctly, see stackoverflow.com/questions/10320232/how-to-accept-a-file-post.

– Igor
Nov 14 '18 at 10:37













Have you tried sending the byte array as string? I've found some example that I used for testing and the JSON that I'm using looks like this: { "ID":46, "Content":"JVBERi0xLjQNCjEgMCBvYm......" } Also, try converting it with this stackoverflow.com/a/11654825/9233618

– Matt
Nov 14 '18 at 13:02





Have you tried sending the byte array as string? I've found some example that I used for testing and the JSON that I'm using looks like this: { "ID":46, "Content":"JVBERi0xLjQNCjEgMCBvYm......" } Also, try converting it with this stackoverflow.com/a/11654825/9233618

– Matt
Nov 14 '18 at 13:02













Also, why don't you set up API method in a way that it accepts just one object containing all data, instead of each parameter individually?

– Matt
Nov 15 '18 at 12:16





Also, why don't you set up API method in a way that it accepts just one object containing all data, instead of each parameter individually?

– Matt
Nov 15 '18 at 12:16













@Matt : Yes of course i can do that.

– Tausif Khan
Nov 16 '18 at 6:12





@Matt : Yes of course i can do that.

– Tausif Khan
Nov 16 '18 at 6:12












1 Answer
1






active

oldest

votes


















0














First, setup your API method in a way that it accepts just one object containing all data instead of each parameter individually.



Instead of:



public HttpResponseMessage Post([FromUri]string AccordDbName, [FromUri]String PayCareDbName, [FromUri]...)


Set it up like:



public HttpResponseMessage Post(Data dataObject)


Secondly, try sending file as a base64string.
Here is example how to do it.



Your file in JSON request should look something like this:



{ "ID":46, 
"Content":"JVBERi0xLjQNCjEgMCBvYm......"
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52780211%2fsending-byte-array-to-api%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    First, setup your API method in a way that it accepts just one object containing all data instead of each parameter individually.



    Instead of:



    public HttpResponseMessage Post([FromUri]string AccordDbName, [FromUri]String PayCareDbName, [FromUri]...)


    Set it up like:



    public HttpResponseMessage Post(Data dataObject)


    Secondly, try sending file as a base64string.
    Here is example how to do it.



    Your file in JSON request should look something like this:



    { "ID":46, 
    "Content":"JVBERi0xLjQNCjEgMCBvYm......"
    }





    share|improve this answer




























      0














      First, setup your API method in a way that it accepts just one object containing all data instead of each parameter individually.



      Instead of:



      public HttpResponseMessage Post([FromUri]string AccordDbName, [FromUri]String PayCareDbName, [FromUri]...)


      Set it up like:



      public HttpResponseMessage Post(Data dataObject)


      Secondly, try sending file as a base64string.
      Here is example how to do it.



      Your file in JSON request should look something like this:



      { "ID":46, 
      "Content":"JVBERi0xLjQNCjEgMCBvYm......"
      }





      share|improve this answer


























        0












        0








        0







        First, setup your API method in a way that it accepts just one object containing all data instead of each parameter individually.



        Instead of:



        public HttpResponseMessage Post([FromUri]string AccordDbName, [FromUri]String PayCareDbName, [FromUri]...)


        Set it up like:



        public HttpResponseMessage Post(Data dataObject)


        Secondly, try sending file as a base64string.
        Here is example how to do it.



        Your file in JSON request should look something like this:



        { "ID":46, 
        "Content":"JVBERi0xLjQNCjEgMCBvYm......"
        }





        share|improve this answer













        First, setup your API method in a way that it accepts just one object containing all data instead of each parameter individually.



        Instead of:



        public HttpResponseMessage Post([FromUri]string AccordDbName, [FromUri]String PayCareDbName, [FromUri]...)


        Set it up like:



        public HttpResponseMessage Post(Data dataObject)


        Secondly, try sending file as a base64string.
        Here is example how to do it.



        Your file in JSON request should look something like this:



        { "ID":46, 
        "Content":"JVBERi0xLjQNCjEgMCBvYm......"
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 10:23









        MattMatt

        324212




        324212






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52780211%2fsending-byte-array-to-api%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Xamarin.form Move up view when keyboard appear

            JBPM : POST request for execute process go wrong