I created a way to upload files using ASP.NET WEBAPI, under the code:
[DataContract] public class FileDesc { [DataMember] public string name { get; set; } [DataMember] public string url { get; set; } [DataMember] public long size { get; set; } [DataMember] public string UniqueFileName { get; set; } [DataMember] public int id { get; set; } [DataMember] public DateTime modifiedon { get; set; } [DataMember] public string description { get; set; } public FileDesc(string rootUrl, FileInfo f,int pId, string aFileName) { id = pId; name = aFileName; UniqueFileName = f.Name; url = rootUrl + "/Files/" + f.Name; size = f.Length / 1024; modifiedon = f.LastWriteTime; description = aFileName; } } public class CustomMultipartFormDataStreamProvider : MultipartFormDataStreamProvider {
and downloading files via Ajax using the jquery.form.js plugin, the code is below:
$('#frmmultiupload').ajaxForm({ success: OnUploadedSuccessfully, error: function (x, y) { mesg('Error occured while file upload! Please make sure that total file size is less than 4 MB and try again.', 'error', 'File upload failed.'); } });
everything works, but creates a problem in IE9
IE says: "Do you want to open or save from the local host?"
The following is the network trace:
I found some tips here , I donβt know how to convert Task<IEnumerable<FileDesc>> to Task<HttpResponseMessage> .
I set a timeout of 30 seconds in ajaxSetup, so after 30 seconds it causes an error.
source share