【问题标题】:Paper clip file upload issue in windows 10Windows 10 中的回形针文件上传问题
【发布时间】:2018-03-10 08:31:16
【问题描述】:

我尝试使用回形针 gem 上传图片时遇到问题。 它在我的 ubuntu 系统上运行良好,但在 Windows 10 上运行良好。 Rails version = 5.1.2Ruby version = 2.2.6p396paperclip = 5.2.1

[回形针] 试图将 C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1yxm99j.png 链接到 C :/用户/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1mjjyje.png [回形针] 链接失败,文件存在 @ sys_fail2 - C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20 180310-5860-1mjjyje.png;复制链接 C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1yxm9 9j.png 到 C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1mjjyje.png 命令 :: file -b --mime "C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1mjjyje.png" [回形针] 内容类型欺骗:文件名 Dog.png(来自标头的图像/png,来自扩展名的 ["image/png"]),从文件命令发现的内容类型:.请参阅文档以允许这种组合。

提前致谢。

【问题讨论】:

    标签: ruby-on-rails paperclip image-upload


    【解决方案1】:

    如您所见:

    [paperclip] Content Type Spoof: Filename Dog.png (image/png from Headers, ["image/png"] from Extension), content type found from file command: . 查看文档允许这种组合。

    Paperclip(或更准确地说,用于识别 Content-Type 的 file -b --mime 命令)静默失败,结果为您留下空字符串。

    它在 Ubuntu 上运行良好,因为您的发行版中包含了 file 程序(您可以使用 man filewhich file 之类的命令来验证这一点)。如果您在 Ubuntu 上运行 sudo apt remove file 然后尝试上传文件,则会导致与上述相同的错误消息。

    如果你想在Windows上使用Paperclip,根据this section,你应该手动安装file并在你的环境变量中添加路径:

    1. this URL下载和安装文件
    2. 转到 GnuWin32 目录并运行 file.exe 以测试它是否有效。
    3. Add file.exe path to your PATH variable 或将 Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin 添加到您的配置/环境中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多