简体   繁体   English

RoR / Refile Gem-无法在Microsoft Edge中加载图像

[英]RoR/Refile Gem - Images not loading in Microsoft Edge

We are using the refile gem to display the images in our platform, they do work well on different browsers except for Microsoft Edge. 我们正在使用refile gem在我们的平台上显示图像,它们在Microsoft Edge以外的其他浏览器上都能正常运行。 Is there a different format or limitation for Microsoft Edge that I should know about it? 我应该了解Microsoft Edge的其他格式或限制吗?

(I don't have Microsoft Edge, so can't test it directly) (我没有Microsoft Edge,因此无法直接对其进行测试)

Any help would be amazing. 任何帮助都将是惊人的。 Thanks. 谢谢。

I've checked with MS Edge 25.10586.0.0 / EdgeHTML 13.10586 and images have not been displayed. 我已经用MS Edge 25.10586.0.0 / EdgeHTML 13.10586检查过,但没有显示图像。

I suppose this happens because images are sent as application/octet-stream and Edge doesn't have enough informations to display them (need to be confirmed). 我想发生这种情况是因为图像是作为应用程序/八位字节流发送的,并且Edge没有足够的信息来显示它们(需要确认)。

But on refile github page you could see it's possible to add metadata for each file loaded like: 但是在refile github页面上,您可以看到可以为加载的每个文件添加元数据,如下所示:

class StoreMetadata < ActiveRecord::Migration
  def change
    add_column :users, :profile_image_filename, :string
    add_column :users, :profile_image_size, :integer
    add_column :users, :profile_image_content_type, :string
  end
end

These fields will be filled automatically after a file load and fixes the issue on my refile example app. 加载文件后,这些字段将自动填充,并在我的重新归档示例应用程序中解决了该问题。

Disclaimer: Be carefull with the following actions, please make some tests before doing this on a production environment 免责声明:请谨慎执行以下操作,在生产环境中进行此操作之前,请进行一些测试

It's possible to add missing informations to your existing files. 可以将丢失的信息添加到现有文件中。

Currently Refile seems to only use filename extension to extract the content-type. 当前, Refile似乎仅使用文件扩展名来提取内容类型。 Therefore we need to extract the content-type with file content and create a filename with the corresponding extension for each uploaded file. 因此,我们需要提取文件内容的内容类型,并为每个上传的文件创建一个具有相应扩展名的文件名。

There is probably many ways to do that. 可能有很多方法可以做到这一点。 I'll describe a method I used on my refile application. 我将描述在重新归档应用程序中使用的方法。

Here is my user model 这是我的用户模型

class User < ActiveRecord::Base
  attachment :profile_image
end

First run the previous migration to add missing fields. 首先运行上一个迁移以添加缺少的字段。

In the gemfile add the gem mimemagic and run bundel install . 在gemfile中,添加gem mimemagic并运行bundel install This one can determine content-type of a file by the content. 这可以通过内容确定文件的内容类型。

Then for each User extract profile_image's content-type and add a correct filename. 然后为每个User提取profile_image的内容类型并添加正确的文件名。

User.all.each do |u|
  subtype = MimeMagic.by_magic(u.profile_image.read).subtype
  u.profile_image_filename = "profile_image.#{subtype}" if u.profile_image_filename.nil?
  u.save
 end

And that's all. 就这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM