问题
I written the below c# code for downloading the attachments in my application, when i run the code i can download the files using Mozilla, internet explorer but this is not working in Google Chrome.
string base64FileString = result;
byte[] binaryFile = Convert.FromBase64String(base64FileString);
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", Request.QueryString["FILENAME"]));
Response.Clear();
Response.BufferOutput = false;
Response.ClearContent();
Response.BinaryWrite(binaryFile);
Response.Flush();
Response.Close();
Can anyone please help me what changes need to do for downloading in Chrome
回答1:
Google Chrome will not open a "file save" window for you if "application/octet-stream"
is your response from a form.
The content-type should be whatever it is known to be, if you know it. E.g. "application/pdf"
, "image/png"
or whatever. See Complete list of MIME types
See this question What could keep Chrome from downloading files? for more information.
来源:https://stackoverflow.com/questions/40003050/failed-network-error-while-downloading-the-files-from-google-chrome