gpt4 book ai didi

c# - 在 MVC 4 中返回下载在 Android 上不起作用

转载 作者:太空狗 更新时间:2023-10-29 15:08:03 25 4
gpt4 key购买 nike

我是第一次张贴,所以请原谅我对张贴技术的无知。我已经搜索了几个小时,但似乎找不到答案,所以希望房间里更聪明的人能帮忙吗?我有一个用 .net MVC 4 编写的 Web 应用程序,它连接到多个云服务 API。然后用户可以从此网络应用程序下载文件。我已经能够让它在除 android 之外的所有平台上运行。当我尝试在 Android 上下载文件时,它挂起并最终失败。下载时它有文件名,但显示 。有人对此有解决方案吗?这是我正在使用的代码:

if (String.IsNullOrEmpty(type))
{
type = "application/octet-stream";
}

byte[] file = openDropBoxFile(path, filename);

if (file != null)
{
return File(file, type, filename);
}

感谢 Slack Shot,遗憾的是它没有改变 android 上的行为。以下是我如何更改代码以防我错误地实现您的解决方案:

if (String.IsNullOrEmpty(type))
{
type = "application/octet-stream";
}

byte[] file = openDropBoxFile(path, filename);
if (file != null)
{
var cd = new System.Net.Mime.ContentDisposition
{
FileName = filename,
Inline = false,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(file, type);
}

关于这个问题的更多信息。我能够下载适用于 Android 的 Firefox,但不适用于 native 浏览器或适用于 Android 的 Google Chrome。

我上次尝试报告的 header ,(我也尝试过不使用 Length 并改用分块传输编码):

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 45113
Content-Type: application/pdf
Server: Microsoft-IIS/8.0
Content-Disposition: attachment; filename="testfile.pdf"
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 09 Nov 2013 17:55:40 GMT

更新:我们已经解决了部分问题!!

事实证明,如果我们关闭 SSL,下载工作正常。有人遇到过这个吗?

最佳答案

您可能想尝试添加 Content-Disposition Header。

       var cd = new System.Net.Mime.ContentDisposition
{
// for example foo.bak
FileName = "Summary.csv",

// always prompt the user for downloading, set to true if you want
// the browser to try to show the file inline
Inline = false,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(model.SummaryDownload.Content().ToArray(), "text/csv");

关于c# - 在 MVC 4 中返回下载在 Android 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19871362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com