Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

So I'm using ng-file-upload to upload file to my api. My problem is that i can't get the api to work.

if i uploaded a small file it works fine. but when its over 50 kb, is not working. I have changed my web config to use

<httpRuntime maxRequestLength="2097151" targetFramework="4.5.2" />
<requestLimits maxAllowedContentLength="2147483648" />

but that don't fix the problem. The code where i post to the api from my controller looks like this.

       Upload.upload({
                        url: 'api/filemanager/upload',
                        file: file,
                        data: dummyobj,
                        //resumeChunkSize: '1MB'
                    }).then(function (resp) {
                        $timeout(function () {
                            console.log('file: ' +
                            resp.config.data.file.name +
                            ', Response: ' + JSON.stringify(resp.data) +
                            '\n');
                            console.log($scope.log)
                        });
                    }, function (e) { alert("error")}, function (evt) {
                        console.log("on notify",evt);
                        var progressPercentage = parseInt(100.0 *
                                evt.loaded / evt.total);
                        $scope.log ='progress: ' + progressPercentage +
                            '% ' + evt.config.data.file.name + '\n'+$scope.log;
                    });

And my web api look like this

        [HttpPost]
        [Route("api/filemanager/upload")]
        public async void FileUpload()
        {

            try
            {

                if (!Request.Content.IsMimeMultipartContent()) Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);

                var path = HttpContext.Current.Server.MapPath("~/appfiles/" + Models.Utilities.Autherize.GetCurrent().App_ID + "/");
                MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(path);

                var streamProvider = await Request.Content.ReadAsMultipartAsync();

                var newFile = new FileModel();

                foreach (var header in streamProvider.Contents)
                {
                    switch (header.Headers.ContentDisposition.Name.Trim('"'))
                    {
                        case "Name":
                            var stream = await header.ReadAsStreamAsync();
                            StreamReader reader = new StreamReader(stream);
                            newFile.Name = reader.ReadToEnd();
                            break;
                        case "Extension":
                            stream = await header.ReadAsStreamAsync();
                            reader = new StreamReader(stream);
                            newFile.Name += "." + reader.ReadToEnd();
                            break;
                        case "file":
                            var imageStream = await header.ReadAsStreamAsync();
                            string destination = path + newFile.Name;

                            using (Stream fileStream = File.Create(destination))
                            {
                                CopyStream(imageStream, fileStream);
                            }
                            break;
                    }


                }
            }
            catch (Exception ex)
            {

                throw;
            }
        }

then we look at what we get on the error of the server side / api. i get a

Error reading MIME multipart body part.

And it's inner error message is

Cannot access a disposed object.

From the client side i get this error from when calling the api

An asynchronous module or handler completed while an asynchronous operation was still pending.

I been looking high and low on the web for a solution for this. and can't find anything useful yet. so i hope someone in here got more experience with this

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.