Resource interpreted as Document but transferred with MIME type application/zip:

17,712

Have you tried changing the request headers, for example the accept header?

Also, here you can find a similar question, some of the solutions suggested there may help you.

Share:
17,712
parliament
Author by

parliament

Serial Entrepreneur Full Stack Developer (C#/AngularJS/D3.js) Contact me if you want to work on cool shit with me. Currently in the bitcoin space, starting a cryptocurrency exchange. Also have a body of work on automated trading systems. [email protected]

Updated on June 04, 2022

Comments

  • parliament
    parliament almost 2 years

    I'm unable to successfully download a file from the server using a Web API get call. The download seems to start but then Chrome throws:

    "Resource interpreted as Document but transferred with MIME type application/zip"

    Firefox doesn't say that but the download still fails.

    What am I doing wrong in the following setup?:

        [HttpGet, Route("api/extractor/downloadresults")]
        public HttpResponseMessage DownloadResultFiles()
        {
            int contentLength = 0;
            this.ResultFiles.ForEach(f => contentLength = contentLength + f.FileSize);
    
            var streamContent = new PushStreamContent((outputStream, httpContext, transportContent) =>
            {
               ...zip files...
            });
    
            streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
            streamContent.Headers.ContentLength = contentLength;
            streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = "result.zip"
            };
    
            var response = Request.CreateResponse();
    
            response.StatusCode = HttpStatusCode.OK;
            response.Content = streamContent;
        }
    

    I trigger the download via:

      window.location.href = "api/extractor/downloadresults";
    

    With the resulting headers:

    Request Headers

      Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
      Accept-Encoding:gzip,deflate,sdch
      Accept-Language:en-US,en;q=0.8
      Connection:keep-alive
      Cookie:ASP.NET_SessionId=ibwezezeutmu2gpajfnpf41p
      Host:localhost:47384
      Referer:http://localhost:47384/
      User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
    

    Response Headers

      Cache-Control:no-cache
      Content-Disposition:attachment; filename=result.zip
      Content-Length:436102
      Content-Type:application/zip
      Date:Mon, 16 Dec 2013 22:36:31 GMT
      Expires:-1
      Persistent-Auth:true
      Pragma:no-cache
      Server:Microsoft-IIS/8.0
      X-AspNet-Version:4.0.30319
      X-Powered-By:ASP.NET
      X-SourceFiles:=?UTF-8?B?QzpcbmV3VG9vbGJveFxUb29sYm94XFRvb2xib3guV2ViXGFwaVx0ZXJtZXh0cmFjdG9yXGRvd25sb2FkcmVzdWx0ZmlsZXM=?=