Coder Social home page Coder Social logo

204 No Content about angular-file-upload HOT 2 CLOSED

nervgh avatar nervgh commented on May 29, 2024
204 No Content

from angular-file-upload.

Comments (2)

kurtfunai avatar kurtfunai commented on May 29, 2024

I'm not familiar with building ASP.NET APIs, but could it be expecting any sort of explicit format?
In Rails you would set the format to json within the url.
ex: '/api/upload' could be '/api/upload.json'

Also, it could be working, but you might not be returning anything.

204 No Content The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

Perhaps debug the controller to see if files is being set?

Sorry I cannot be of more help :[

from angular-file-upload.

parvinderahlawat avatar parvinderahlawat commented on May 29, 2024

Thanks Kurt, I was able to resolve this issue.
I verified that the files were being set properly in the angular_file_uploader item object so issue was at the receiving end.

I didn't had to specify any additional property, other than the headers tag to fix one exception.

var headers = { "Content-Type": "multipart/form-data" };
var uploader = $scope.uploader = $fileUploader.create({
    scope: $scope,                          
    url: '/upload/UploadDocuments',
    method: 'POST',
    headers: headers
});

If any other .NET person facing the same issue, I was able to resolve this by doing the POST request to a normal controller instead of a Web API controller, and read it from the Request object:

Action being called from fileUploader:
[HttpPost]
public void UploadDocuments()

and then reading the files using below code:
string filename = null;
string fileType = null;
byte[] fileContents = null;
string fileMetadata = Request.Headers["X-File-Metadata"];
if (Request.Files.Count > 0)
{
var file = Request.Files[0];
fileContents = new byte[file.ContentLength];
file.InputStream.Read(fileContents, 0, file.ContentLength);
fileType = file.ContentType;
filename = file.FileName;
}
else if (Request.ContentLength > 0)
{
fileContents = new byte[Request.ContentLength];
Request.InputStream.Read(fileContents, 0, Request.ContentLength);
filename = Request.Headers["X-File-Name"];
fileType = Request.Headers["X-File-Type"];
}

from angular-file-upload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.