0

I'm using Postman and my own Restsharp based client to send the audio file to the web API controller when size exceeded from 3 or 4 MB provider.FileData showing contains 0 files.

I also tried to use this but can't be solved the problem. var provider = new MultipartFileStreamProvider(root);

    public async Task<HttpResponseMessage> UploadFile()
    {
        HttpRequestMessage request = this.Request;
        if (!request.Content.IsMimeMultipartContent())
        {
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
        }

        string root = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/uploads");
        var provider = new MultipartFormDataStreamProvider(root);

        var task = await request.Content.ReadAsMultipartAsync(provider).
            ContinueWith<HttpResponseMessage>(o =>
                {
                    FileInfo finfo = new FileInfo(provider.FileData.First().LocalFileName);
                    string guid = Guid.NewGuid().ToString();
                    string fileName = guid + "_" + provider.FileData.First().Headers.ContentDisposition.FileName
                                          .Replace("\"", "");
                    File.Move(finfo.FullName, Path.Combine(root, fileName));

                    return new HttpResponseMessage()
                    {
                        Content = new StringContent("File uploaded.")
                    };
                }
            );

        return task;
    }
Malik Qasim
  • 61
  • 2
  • 3
  • the max length is `4MB` you can increase file length in `web.config` file by `maxRequestLength`, possible duplicate of https://stackoverflow.com/questions/288612/how-to-increase-the-max-upload-file-size-in-asp-net – Aria Dec 30 '18 at 11:12
  • 1
    @Aria thanks i have solved it throught adding the **** in system.web area of web.config file. – Malik Qasim Dec 30 '18 at 12:35

0 Answers0