活动存储

编程入门 行业动态 更新时间:2024-10-15 02:26:06
本文介绍了活动存储 - 防止下载 - 尽可能在浏览器中打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 rails_blob_url(o.audio_file) 但它很烦人,因为 url 不会在浏览器中打开文件而是将文件作为附件下载(这不是音频文件的默认浏览器行为).

我希望浏览器随心所欲地打开文件.我不想强制下载文件...

rails_blob_url(o.audio_file, disposition: :inline)

不起作用.

解决方案

除了使用 rails_blob_url(o.audio_file, disposition: :inline) 您还必须允许内容类型.

Rails.application.config.active_storage.content_types_allowed_inline += ["音频/mp3","音频/mp4",音频/mpeg"]

此时默认的内容类型为:["image/png", "image/gif", "image/jpg", "image/jpeg", "image/tiff", "image/bmp"", "image/vnd.adobe.photoshop", "image/vnd.microsoft.icon", "application/pdf"] 所以我不得不添加所有的音频.

关于它的更多信息这里

I am using rails_blob_url(o.audio_file) but it is annoying since url doesn't open file in browser but downloads the file as an attachment (this is not a default browser behaviour for audio files).

I want that browser opens the file however it wants. I do not want to force download file ...

rails_blob_url(o.audio_file, disposition: :inline)

Doesn't work.

解决方案

In addition to using rails_blob_url(o.audio_file, disposition: :inline) you also have to allow the content type.

Rails.application.config.active_storage.content_types_allowed_inline += [ "audio/mp3", "audio/mp4", "audio/mpeg" ]

At this time the default content types are: ["image/png", "image/gif", "image/jpg", "image/jpeg", "image/tiff", "image/bmp", "image/vnd.adobe.photoshop", "image/vnd.microsoft.icon", "application/pdf"] so I had to add all the audio ones.

There's a little bit more info about it here

更多推荐

活动存储

本文发布于:2023-11-30 16:51:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!