Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

rest - What is the best way to pass an Excel file to a WEB API web service

I need to pass an Excel file in to and web service implemented in C#. The web service I have created so far is as follows.

 public void loadData([FromBody]string dataFile)
        {

        }

I also thought that it is accepatble to pass the Excel file is using a Base64 string; Is this a good way or are there any better ways to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Basically, you pass the file as part of a multipart/form-data HTTP request.

How To Accept a File POST

Sending HTML Form Data in ASP.NET Web API: File Upload and Multipart MIME

Edit: To receive a binary file of any type, use the following code. However, this is fairly unsafe. Really, the request headers should be checked for content type and content length.

public void loadData() {
    /* get raw data */
    string dataFile = Request.Content.ReadAsStringAsync().Result
}

Accepting Raw Request Body Content with ASP.NET Web API


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...