ActiveStorage raw file uploads fail with "An unknown file format not allowed" due filename being lost

未关闭
#591 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
rails, ruby
领域
backend

调研方向

从 lib/active_storage/service/cloudinary_service.rb 中的 upload 方法开始,检查 ActiveStorage 文件名如何传递到 Cloudinary::Uploader.upload_large。复现 issue 中描述的已配置 CSV 上传,按描述保留原始文件名,并验证 ActiveStorage 上传能够完成且不会出现未知文件格式错误。

由索引模型根据 Issue 内容生成。

描述

Bug report for Cloudinary Ruby SDK

Before proceeding, please update to latest version and test if the issue persists

Describe the bug in a sentence or two.

When uploading raw files (e.g. CSV) through the ActiveStorage integration, the Cloudinary API rejects the upload with CloudinaryException: An unknown file format not allowed.

This is a regression from the 1.x series, which used rest-client and preserved the original filename in multipart requests.

Issue Type (Can be multiple)

  • Build - Cannot install or import the SDK
  • Performance - Performance issues
  • Behaviour - Functions are not working as expected (such as generate URL)
  • Documentation - Inconsistency between the docs and behaviour
  • Other (Specify)

Steps to reproduce

  1. Configure ActiveStorage with the Cloudinary service (config/storage.yml):
   cloudinary:
     service: Cloudinary
     type: private
  1. Configure a Cloudinary upload preset as the default for "API raw" with allowed_formats: ["csv"]
  2. Create a model with has_one_attached :csv_file
  3. Upload a .csv file through ActiveStorage
  4. Observe the error:
   ActiveStorage::IntegrityError (An unknown file format not allowed)
   Caused by: CloudinaryException (An unknown file format not allowed)

Error screenshots or Stack Trace (if applicable)

…

Operating System

  • Linux
  • Windows
  • macOS
  • All

Environment and Libraries (fill in the version numbers)

  • Cloudinary Ruby SDK version - 2.1.2
  • Ruby Version - 3.4.1
  • Rails Version - 8.1.2
  • Other Libraries (Carrierwave, ActiveStorage, etc) - 0.0.0

Repository

If possible, please provide a link to a reproducible repository that showcases the problem

Suggested Fix

In lib/active_storage/service/cloudinary_service.rb, the upload method should pass the filename to the uploader as original_filename:

def upload(key, io, filename: nil, checksum: nil, **options)
  instrument :upload, key: key, checksum: checksum do
    begin
      extra_headers = checksum.nil? ? {} : {Headers::CONTENT_MD5 => checksum}
      options = @options.merge(options)
      options[:original_filename] = filename.to_s if filename.present?  # <-- add this
      resource_type = resource_type(io, key)
      options[:format] = ext_for_file(key) if resource_type == "raw"
      Cloudinary::Uploader.upload_large(
        io,
        # ... rest unchanged
      )
    end
  end
end
主要语言
Ruby
星标
420
派生
282
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cloudinary/cloudinary_gem 的其他 Issue

查看 cloudinary/cloudinary_gem 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。