0

I am receiving an error trying to upload large than 50kB file via jQuery Ajax POST request. I am sending the request to OData service ( ASP.Net MVC application)

The error I am receiving in browser console is " 413 Request Entity Too Large "

Below is the code I am using to upload

  var fileData =
        {
            fileBinaryData:  encodedData //file data in encoded format ( 64 bit),
            Description: "my first file"
        };

    fileData = JSON.stringify(fileData);

 $.ajax({
     url: // some odata url ,
     type: "POST",
     data: fileData,
     success: function (res) {
        // do something
     },
     contentType: "application/json",
     beforeSend: function (xhr) {
         xhr.setRequestHeader("Accept", "application/json");
     }
 });

a) Is code above the correct way to upload file data via jQuery ajax to a service b) I have modified my web.config to accept large requests. c) I do not want to use plugin's like uploadify etc

EDIT 1: I used javascripts' FileReader() to read the file.

 var reader = new FileReader();

    //then applied reader.onloadend method etc
    if (file.webkitSlice) {               
         var blob = file.slice(start, stop + 1);
     } else if (file.mozSlice) {
         var blob = file.mozSlice(start, stop + 1);
     }    
    reader.readAsBinaryString(blob);
Atur
  • 1,712
  • 6
  • 32
  • 42
  • The size of the uploaded file can be upto 50 MB. – Atur Feb 05 '13 at 11:19
  • Also the ODATA url is similar to https://mywebsite.com/api/FileDocuments(1001) Where FileDocument is a class which contains properties `public Byte[] FileBinaryData {get;set;} public string Description {get;set;}` – Atur Feb 05 '13 at 11:22
  • Even when I tried the [link](http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload) i received similar issues. – Atur Feb 05 '13 at 11:37

1 Answers1

0

Finally settled with using jQuery fileUpload plugin

Atur
  • 1,712
  • 6
  • 32
  • 42