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

Aperta
#591 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
rails, ruby
Ambito
backend

Direzione di ricerca

Inizia in lib/active_storage/service/cloudinary_service.rb, nel metodo upload, e verifica come il nome file di ActiveStorage arriva a Cloudinary::Uploader.upload_large. Riproduci l'upload CSV configurato descritto nell'issue, preserva il nome file originale come descritto e verifica che l'upload di ActiveStorage venga completato senza l'errore di formato file sconosciuto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Ruby
Stelle
420
Fork
282
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudinary/cloudinary_gem

Tutte le issue di cloudinary/cloudinary_gem

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.