angular-file-upload icon indicating copy to clipboard operation
angular-file-upload copied to clipboard

Error

Open mdemarco1234 opened this issue 8 years ago • 1 comments

Hello,

I am getting an error when the file is posted. I am using WebApi and C#.  

"Unexpected end of MIME multipart stream. MIME multipart message is not complete". Code I have tried is below. Some of it is commented out but the latest is not. Tried all the code to no avail.

Regards,

Michael

    [HttpPost]
    [Route("api/fileupload/post")]
    public async Task<IHttpActionResult> Post()
    {
        
        _sRoot = @"c:\notesgenius";

        // ensure that the request contains multipart/form-data
        if (!Request.Content.IsMimeMultipartContent("form-data"))
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);

        //if (!Directory.Exists(_sRoot)) Directory.CreateDirectory(_sRoot);
        //MultipartFormDataStreamProvider provider =
        //    new MultipartFormDataStreamProvider(_sRoot);

        try
        {

            System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;


            //Stream reqStream = Request.Content.ReadAsStreamAsync().Result;
            //MemoryStream tempStream = new MemoryStream();
            //reqStream.CopyTo(tempStream);

            //tempStream.Seek(0, SeekOrigin.End);
            //StreamWriter writer = new StreamWriter(tempStream);
            //writer.WriteLine();
            //writer.Flush();
            //tempStream.Position = 0;

            var provider = new CustomMultipartFormDataStreamProvider(_sRoot);

            //StreamContent streamContent = new StreamContent(tempStream);
            //foreach (var header in Request.Content.Headers)
            //{
            //    streamContent.Headers.Add(header.Key, header.Value);
            //}

            //// Read the form data and return an async task.
            //await streamContent.ReadAsMultipartAsync(provider);


            await Request.Content.ReadAsMultipartAsync(provider);
            await Task.Run(async () => await Request.Content.ReadAsMultipartAsync(provider));


            //Stream reqStream = Request.Content.ReadAsStreamAsync().Result;
            //MemoryStream tempStream = new MemoryStream();
            //reqStream.CopyTo(tempStream);

            await Request.Content.ReadAsMultipartAsync(provider);
            int nChunkNumber = Convert.ToInt32(provider.FormData["flowChunkNumber"]);
            int nTotalChunks = Convert.ToInt32(provider.FormData["flowTotalChunks"]);
            string sIdentifier = provider.FormData["flowIdentifier"];
            string sFileName = provider.FormData["flowFilename"];

            // rename the generated file
            MultipartFileData chunk = provider.FileData[0]; // Only one file in multipart message
            RenameChunk(chunk, nChunkNumber, sIdentifier);

            // assemble chunks into single file if they're all here
            TryAssembleFile(sIdentifier, nTotalChunks, sFileName);

            return Ok();
        }
        catch (Exception ex)
        {
            return InternalServerError(ex);
        }
    }

mdemarco1234 avatar Apr 17 '17 02:04 mdemarco1234

Any update on this? I am facing the same issue.

vpetrovic avatar Sep 25 '17 14:09 vpetrovic