【发布时间】:2020-07-27 20:03:06
【问题描述】:
我在我的 rails 应用程序中定义了一个上传器。我在这里面临的问题是,当我下载上传的文件时,它会下载为 PDF 而不是文件的实际格式。
class DocumentController < MyAccountController
def show
@agency = current_agency
redirect_to @agency.document.url
end
end
这是文件的网址。但文件总是以 PDF 格式下载
"http://localhost:3000/uploads/agency/document/61/document.jpeg"
文件下载方法
<script>
downloadDocument() {
var url = 'myagency/document',
fileName = "EngagementLetter",
file;
this.$axios.get(url, { responseType: 'blob' })
.then(response => {
file = new Blob(
[response.data],
{ type: 'application/pdf, image/gif, image/jpeg' }
);
FileSaver.saveAs(file, fileName);
});
}
</script>
【问题讨论】:
标签: ruby-on-rails vue.js carrierwave