cloudinary / cloudinary/cloudinary_gem

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

Abierto
#591 3 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Ruby
Estrellas
420
Forks
285
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## 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
- [x] 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
```

2. Configure a Cloudinary upload preset as the default for "API raw" with allowed_formats: ["csv"]
3. Create a model with has_one_attached :csv_file
4. Upload a .csv file through ActiveStorage
5. 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
- [x] 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:

```ruby
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
```

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Start in lib/active_storage/service/cloudinary_service.rb at the upload method and review how the ActiveStorage filename reaches Cloudinary::Uploader.upload_large. Reproduce the configured CSV upload from the issue, preserve the original filename as described, and verify that the ActiveStorage upload completes without the unknown file format error.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rails, ruby
Área
backend
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
52/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.