无法在网页中打开下载的文件嵌入文件 link,因为文件格式或扩展名无效
Unable to open downloaded file embedded file link in a webpage because file format or extension is not valid
我的客户要求我在我的 react/django 站点中嵌入一个 link 用于可下载的 excel,不幸的是,只要我 运行 我的站点上的该站点,下载就可以进行本地,但部署后您可以成功下载 link,但无论何时打开它,excel 都会弹出一个弹出窗口,提示“Excel 无法打开文件 'filename',因为文件format or file extension is not valid. 验证文件没有损坏,文件扩展名是否与文件格式匹配。我已经检查了GAE上构建目录中的文件,扩展名仍然是.xlsx,下载后,我仍然在我的下载文件夹中看到 .xlsx 扩展名。我什至尝试将 excel 转换为 pdf 并嵌入 link,虽然这在我的本地仍然有效,但之后部署我得到“无法打开文件。”
我不确定这是否真的与部署或 django 中的某些配置设置有关,或者像需要在 app.yaml 中指定静态图像一样让我感到困惑。我已经在他们的网站上搜索了关于该主题的文档:https://cloud.google.com/appengine/docs/flexible/python/reference/app-yaml 没有任何东西跳出来作为我错过的配置来解决这个问题。
link 使用以下标签嵌入到我的站点中:
<p> Here is a partial list of completed projects. Download the <a href="/files/ReferenceListCopy.pdf" download>link</a> for the full list. </p>
我希望这是我错过的简单内容。在此先感谢您的帮助。
我会将文件放在您的 /static
目录中,并将其作为静态文件提供。将此添加到 app.yaml
:
- url: /static/(.*\.(xlsx|xls))
static_files: static/
upload: static/(.*\.(xlsx|xls))
并通过以下方式访问:<a href="/static/ReferenceListCopy.xlsx" download>link</a>
如果您仍然遇到问题,请尝试:
- url: /static/(.*\.xls)
mime_type: application/vnd.ms-excel
static_files: static/
upload: static/(.*\.xls))
- url: /static/(.*\.xlsx)
mime_type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
static_files: static/
upload: static/(.*\.xlsx)
您可以为 pdf
s 做同样的事情:
- url: /static/(.*\.pdf)
mime_type: application/pdf
static_files: static/
upload: static/(.*\.pdf)
我的客户要求我在我的 react/django 站点中嵌入一个 link 用于可下载的 excel,不幸的是,只要我 运行 我的站点上的该站点,下载就可以进行本地,但部署后您可以成功下载 link,但无论何时打开它,excel 都会弹出一个弹出窗口,提示“Excel 无法打开文件 'filename',因为文件format or file extension is not valid. 验证文件没有损坏,文件扩展名是否与文件格式匹配。我已经检查了GAE上构建目录中的文件,扩展名仍然是.xlsx,下载后,我仍然在我的下载文件夹中看到 .xlsx 扩展名。我什至尝试将 excel 转换为 pdf 并嵌入 link,虽然这在我的本地仍然有效,但之后部署我得到“无法打开文件。”
我不确定这是否真的与部署或 django 中的某些配置设置有关,或者像需要在 app.yaml 中指定静态图像一样让我感到困惑。我已经在他们的网站上搜索了关于该主题的文档:https://cloud.google.com/appengine/docs/flexible/python/reference/app-yaml 没有任何东西跳出来作为我错过的配置来解决这个问题。
link 使用以下标签嵌入到我的站点中:
<p> Here is a partial list of completed projects. Download the <a href="/files/ReferenceListCopy.pdf" download>link</a> for the full list. </p>
我希望这是我错过的简单内容。在此先感谢您的帮助。
我会将文件放在您的 /static
目录中,并将其作为静态文件提供。将此添加到 app.yaml
:
- url: /static/(.*\.(xlsx|xls))
static_files: static/
upload: static/(.*\.(xlsx|xls))
并通过以下方式访问:<a href="/static/ReferenceListCopy.xlsx" download>link</a>
如果您仍然遇到问题,请尝试:
- url: /static/(.*\.xls)
mime_type: application/vnd.ms-excel
static_files: static/
upload: static/(.*\.xls))
- url: /static/(.*\.xlsx)
mime_type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
static_files: static/
upload: static/(.*\.xlsx)
您可以为 pdf
s 做同样的事情:
- url: /static/(.*\.pdf)
mime_type: application/pdf
static_files: static/
upload: static/(.*\.pdf)