locked
Question on acepting long coma delimited csv string in body of post method RRS feed

  • Question

  • User2001833234 posted

    Could someone help:  I have an  Angular 2 app with the following issue.  I would like to add functionality where the user can click a button and send a csv file as an attachtment via email.  From what I have found, this is not an easy task with Angular 2 or JavaScript. 

    Thus my question:

    Would it make sense for me to have an Web API POST method that accepts a long comma delimited string in the body (I would assume I need to set the Content-type: application/text to do that).  And then I could create the file and send the email in C#.  The bad part of this design is that First my Web API would be calling the db and sending a Json result, then the client would be sending the data back to the API as a coma delimited string to be converted to a file and emailed. 

    Note: I thought about just sending the get parameter  and making the db call again, but these queries take long enough as it is and the delay could be an issue.

    Any thoughts or advice would be greatly appreciated.

    Thank You.

    Friday, December 2, 2016 4:36 AM

Answers

  • User2001833234 posted

    Chris/ To anyone concerned.

         Thank you for your response.  I actually did come up with a solution.  I ended up creating a Web API that accepts a string of data in the body.

    I used [FromBody] to get the data.  Then I use Angular 2 http.Post to send it with Content-Type: application/json and my Accept: application/json.

    Works Awesome.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 6, 2016 4:19 PM

All replies

  • User-2057865890 posted

    Hi Duckkiller53,

    You could consider adding the file content to FormData's collection and making an jQuery AJAX request to Web API action.

    reference:

    https://www.codeproject.com/articles/806075/file-upload-using-jquery-ajax-in-asp-net-web-api 

    Best Regards,

    Chris

    Tuesday, December 6, 2016 2:26 AM
  • User2001833234 posted

    Chris/ To anyone concerned.

         Thank you for your response.  I actually did come up with a solution.  I ended up creating a Web API that accepts a string of data in the body.

    I used [FromBody] to get the data.  Then I use Angular 2 http.Post to send it with Content-Type: application/json and my Accept: application/json.

    Works Awesome.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 6, 2016 4:19 PM