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

Đang mở
#591 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rails, ruby
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu trong lib/active_storage/service/cloudinary_service.rb tại phương thức upload và kiểm tra cách tên tệp của ActiveStorage được truyền đến Cloudinary::Uploader.upload_large. Tái hiện thao tác tải lên CSV đã được cấu hình như mô tả trong issue, giữ nguyên tên tệp ban đầu như đã mô tả và xác minh rằng thao tác tải lên của ActiveStorage hoàn tất mà không gặp lỗi định dạng tệp không xác định.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Ruby
Star
420
Fork
282
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của cloudinary/cloudinary_gem

Tất cả issue của cloudinary/cloudinary_gem

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.