Dinesh Kumar
asked on
File Upload on Server through a webservice
Hi, I want through following service and tested it also using Fiddler.
http://blog.anthonybaker.me/2013/06/how-to-implement-file-upload-restful.html
1. I am wondering, if we don't use fiddler, how the client is going to send files because in fiddler I can see Upload files button.
2. or should I prefer making action which takes encoded contents of file as bytes?
http://blog.anthonybaker.me/2013/06/how-to-implement-file-upload-restful.html
1. I am wondering, if we don't use fiddler, how the client is going to send files because in fiddler I can see Upload files button.
2. or should I prefer making action which takes encoded contents of file as bytes?
If you have a REST API, then what does the web method take as an argument? What does the "client" refer to?
ASKER
1. so in other words, how to upload file to that REST API
2. Client can be .net client, php client, jquery
2. Client can be .net client, php client, jquery
ASKER
The following code I am trying, but it is saving some file which I can not read..
public async Task<HttpResponseMessage> Post()
{
// Check if the request contains multipart/form-data.
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
try
{
// Read the form data.
await Request.Content.ReadAsMultipartAsync(provider);
// This illustrates how to get the file names.
foreach (MultipartFileData file in provider.FileData)
{
Trace.WriteLine(file.Headers.ContentDisposition.FileName);
Trace.WriteLine("Server file path: " + file.LocalFileName);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
catch (System.Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
}
}
It looks like you are using the code from this article:
Sending HTML Form Data in ASP.NET Web API: File Upload and Multipart MIME
http://www.asp.net/web-api/overview/advanced/sending-html-form-data,-part-2
How are you sending the multi-part form data?
Sending HTML Form Data in ASP.NET Web API: File Upload and Multipart MIME
http://www.asp.net/web-api/overview/advanced/sending-html-form-data,-part-2
How are you sending the multi-part form data?
ASKER
I am using fiddler to upload file.
ASKER
I need to upload any file, let it be excel, text file or pdf.. by using oData service.
ASKER
Just created another question :( with slight difference..
ASKER
I don't think that the problem is with the web service. I think that the problem is with the call from Fiddler. What are you using for arguments?
ASKER
I am using the same way as I tested following and that worked with mvc application.
http://blog.anthonybaker.me/2013/06/how-to-implement-file-upload-restful.html
method: post
url provided
and click on upload files and execute..
http://blog.anthonybaker.me/2013/06/how-to-implement-file-upload-restful.html
method: post
url provided
and click on upload files and execute..
ASKER
oh the problem is that the file was renamed while saving and there was no extention. the type of the file was file
so when I uploaded excel, I opened the saved file in excel, it opened.
so It seems the tasks remaining are to apply the extension and keep the same name as uploaded.
so when I uploaded excel, I opened the saved file in excel, it opened.
so It seems the tasks remaining are to apply the extension and keep the same name as uploaded.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
finally its working..