uploader.read returns an empty string

Open
#175 0 comments 0 reactions 1 assignee View on GitHub

@d-mendoza is already working on this.

Since Mar 3, 2021.

Assessment

This issue has not been assessed yet.

Description

question

I use cloudinary 1.1.0 with carrierwave 0.10.0 in a rails 4.2.4 app to store PDFs.

I get the following bug

record.pdf.read # => ""

I digged a bit into the code base and realised that the Uploader's identifier was not the same as the Cloudinary::CarrierWave::CloudinaryFile's identifier

record.pdf.identifier # => v1444643650/foo.pdf
record.pdf.file.identifier # => image/upload/v1444643650/foo.pdf

Internally, pdf.read calls pdf.file.read which is defined as

def read(options={})
  parameters={:type=>self.storage_type, :resource_type=>self.resource_type}.merge(options)
  Cloudinary::Downloader.download(self.identifier, parameters)
end

Cloudinary::Downloader.download then gives Cloudinary::Utils.cloudinary_url the passed identifier to generate the URL to read data from.

But the generated URL is wrong when the identifier is pdf.file.identifer. I tried with the uploader's identifier and it worked.

Cloudinary::Utils.cloudinary_url pdf.identifier
# => http://res.cloudinary.com/cloud_name/image/upload/v1444643650/foo.pdf

Cloudinary::Utils.cloudinary_url pdf.file.identifier
# => http://res.cloudinary.com/cloud_name/image/upload/v1/image/upload/v1444643650/foo.pdf

Hope this helps to fix the bug

Dominant language
Ruby
Stars
420
Forks
282
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudinary/cloudinary_gem

All issues in cloudinary/cloudinary_gem

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.