Note that there are some explanatory texts on larger screens.

plurals
  1. POZip file not downloading after zip was correctly filled but contentlength is empty
    primarykey
    data
    text
    <p>On my page I currently have the following: a webgrid with some invoices, for every invoice I have a checkbox, for every invoice I have a pdf-Icon to view the pdf in the browser or to download the pdf.</p> <p>What I'm trying to accomplish is that the user has the possibility to check some invoices and hit the button below to download these invoices as a ZIP file. </p> <p>When the button is clicked an jquery function is called, this function makes an AJAX-call to my ASP.net. I pass an arrayparameter of the corresponding ID's of the invoice.</p> <h2>jQuery - Ajax-call</h2> <pre><code>$("#download").click(function () { var idArray = []; $("input[type=checkbox]").each(function () { if (this.checked) { idArray.push($(this).val()); } }); $.ajax({ traditional: true, type: "GET", url: "/Invoices/downloadInvoices", data: { idArray: idArray }, error: function () { alert("error"); } }).done(function (data) { console.log("succes download function"); }); }); </code></pre> <p>This function works as expected, in my controller I receive the array. The next step is to get the corresponding files (base64 from database) convert these files and put these file into the ZIP. This works aswell, when i check the entries of the ZIP it has the right content.</p> <h2>Controller</h2> <pre><code> public ActionResult downloadInvoices(string[] idArray) { MemoryStream outputStream = new MemoryStream(); outputStream.Seek(0, SeekOrigin.Begin); using (ZipFile zip = new ZipFile()) { foreach (string id in idArray) { string json = rest.getDocumentInvoice(Convert.ToInt32(id)); byte[] file = json.convertJsonToFile(); zip.AddEntry("invoice" + id + ".pdf", file); } zip.Save(outputStream); } outputStream.WriteTo(Response.OutputStream); Response.AppendHeader("content-disposition", "attachment; filename=invoices.zip"); Response.ContentType = "application/zip"; //return File(outputStream, "application/zip", fileDownloadName:"invoices.zip"); -- DIDN'T WORK return new FileStreamResult(outputStream, "application/zip") { FileDownloadName = "invoices" }; } </code></pre> <p>The last step I need is that the user sees the popup to save the zip-file but this doesn't happen. When I check my debugger the ajaxcall is completed succesfully. When I check the debugger (headers) I see the request but the response headers shows contentlength : 0.</p> <p>What am I missing, couldn't find any solution on the net. Hope u can help me.</p> <p>Thanks in advance</p> <h2>EDIT</h2> <p>{ FileDownloadName = "invoices" }</p> <p>When this piece of code is deleted my contentlength isn't 0 anymore. But how can this file now be downloaded? The content the request is sending looks like the file but the popup to download the file isn't showing. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload