4

I need to upload a file to server from a wpf application, the file path would be same always, so it would be simple if web api expected file path only.

But the web api method looks like this:

 // POST api/values
 [HttpPost]
 public IActionResult UploadFile(IFormFile file)
 {
    // Upload logic goes here.
 }

So I am not sure how to create an object of type IFormFile from the file path which I have.

Note: IFormFile interface is there in Microsoft.AspNet.Http namespace.

5
  • I presume the IFormFile interface is something developed by who created the Web Method, probably this interface implements some Methods and properties and what you need to do is create a class that implements that interface putting the information of the file you want to load inside the class and passing it to the web method. Commented Mar 1, 2016 at 9:24
  • This interface is there in Microsoft.AspNet.Http namespace. I edited my question. Commented Mar 1, 2016 at 9:34
  • Ok the answer is the same, you have to create an instance of a class implementing the IFormFile interface (or create a new one) and this interface probably contains the properties to indicate the name of your file, passing then the class to your web method your upload file method should succeed. Commented Mar 1, 2016 at 10:39
  • Being curious, I've made a little search on IFormFile interface and I found little to nothing, but what I noticed about it is that anything related to it is Connected to Uploading files using Web Forms (in ASP.Net UI interfaces), so maybe what you are trying to use is not exactly the right thing? Commented Mar 1, 2016 at 10:52
  • @Sabrina_cs, yes I am thinking the same, may be web api shouldn't have been exposing a method which expects IFormFile object. That looks purely to be consumed by the web applications. Commented Mar 1, 2016 at 11:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.