coldfusion - cfcontent 强制下载不向浏览器报告文件大小

标签 coldfusion download

我创建了一个页面以允许我们的客户下载文件。麻烦的是,浏览器不知道文件有多大,也不显示下载进度...

如何让 ColdFusion 至少报告文件大小?而且,充其量,我如何让浏览器下载栏检测文件大小和下载进度?

这是我的代码。

<cfparam name="delete_file" default="no">
<cfparam name="URL.d" default="n">
<cfparam name="content_type" default="image/jpeg">
<cfparam name="FileDownload" default="default.jpg">
<cfparam name="URL.file" default="default.jpg">
<cfparam name="folder" default="downloads">
<cfparam name="URL.folder" default="downloads">
<cfset folder = #URL.folder#>
<cfset FileDownload = #URL.file#>
<cfif URL.d IS "y">
    <cfset delete_file = "yes">
<cfelse>
    <cfset delete_file = "no">
</cfif>
<cfset exten = ListLast(FileDownload, ".")>

<cfswitch expression="#exten#">
<cfcase value="zip"><cfset content_type = "application/zip, application/x-zip, application/x-zip-compressed, application/octet-stream, application/x-compress, application/x-compressed, multipart/x-zip"></cfcase>
<cfcase value="ai"><cfset content_type = "application/illustrator"></cfcase>
<cfcase value="eps"><cfset content_type = "application/illustrator, application/octect-stream"></cfcase>
<cfcase value="pdf"><cfset content_type = "application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf"></cfcase>
<cfcase value="psd"><cfset content_type = "image/photoshop, image/x-photoshop, image/psd, application/photoshop"></cfcase>
<cfcase value="jpg"><cfset content_type = "image/jpeg"></cfcase>
<cfcase value="png"><cfset content_type = "image/png"></cfcase>
<cfcase value="tif"><cfset content_type = "image/tiff"></cfcase>
<cfdefaultcase><cfset content_type = "image/jpeg"></cfdefaultcase>
</cfswitch>

<cfoutput><cfheader name="content-disposition" value="attachment;filename=#FileDownload#">
<cfcontent type="#content_type#" file="#ExpandPath("./#folder#")#/#FileDownload#" deletefile="#delete_file#"></cfoutput>

最佳答案

<cfset fileToGetSizeOf = expandPath("./#folder#/#FileDownload#") />
<cfheader name="content-length" value="#getFileInfo(fileToGetSizeOf ).size#" />

应该做

关于coldfusion - cfcontent 强制下载不向浏览器报告文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10825959/

相关文章:

json - 如何为图表中的所有文本设置字体属性?

ColdFusion 对象到字符串

c# - 多应用服务器环境和 Memcached 安全

javascript - 非javascript定时器

c# - WebClient DownloadFileAsync 挂起

html - 表格仅在第一次发送

video - 通过实际代码从具有 .TS 或 .m3u8 文件路径的视频流中下载内容视频,以便我可以制作 chrome 扩展

linux - 为什么最后一段 HTTP 下载真的很慢?

coldfusion - 如何获取在 ColdFusion 中扩展我的组件的名称?

android - 使用 Retrofit 从 Url 下载视频