My app is: NET Core 5 Web service. I need to pass to HTTP PUT method a csv file. The csv is like string1, string2, string3.
As one way I see: upload the csv file and then parse it to corresponding class. But what else way? How to pass the string list in RESTful API?
CodePudding user response:
Assuming your string list is longer than an URL should be, you define a body:
public class Model
{
public List<string> StringList { get; set; }
}
Then in your controller, you chose a HTTP method that accepts a body (PUT/POST most likely):
[HttpPost]
public IActionResult YourMethod([FromBody] Model model)
{
// and here, you can access model.StringList
}
Please note that an XLS or even CSV file is not just a string list. You would be better served by uploading the file and using an actual parser package that can handle that file format.