Coder Social home page Coder Social logo

Comments (17)

igy avatar igy commented on June 11, 2024

Hi Miguel,

Thanks for contacting us.

I hate to ask a potentially silly question, but are you certainly using v1.21.0 of the SDK in both your production and development environments?

I ask because v1.19.0 of the Ruby SDK included a bugfix to resolve an issue that's very similar to what you've described here, and earlier versions can be expected to have this error in the scenario you've described.

The code that was added and an accompanying note can be seen here:

# Provide file format for raw files, since js client does not include original file name.
#
# When the file is uploaded from the server, the request includes original filename. That allows Cloudinary
# to identify file extension and append it to the public id of the file (raw files include file extension
# in their public id, opposed to transformable assets (images/video) that use only basename). When uploading
# through direct upload (client side js), filename is missing, and that leads to inconsistent/broken URLs.
# To avoid that, we explicitly pass file format in options.
options[:format] = ext_for_file(key) if options[:resource_type] == "raw"
options[:context] = {active_storage_key: key}
options.delete(:file)
payload[:url] = api_uri("upload", options)

If you do have v1.21.0 (or some other version above 1.19.0), were you able to identify any common factor for the requests that fail? Is the upload filename, including the extension, certainly available to your frontend code, for it to be passed to our SDK and from there to our API?

Thanks,
Stephen

from cloudinary_gem.

Mrodrides avatar Mrodrides commented on June 11, 2024

Hello @igy thanks for your answer,

I tried to even lock the version in the gemfile gem 'cloudinary', '~> 1.21.0' but it didn't work It does not detect.
Ive unpacked the gem and debugged using byebug, i found the following results:
image
Here content_type is '' as io is nil and the key is just a string, this method is called here

image

thus when calling content_type_to_resource_type with content_type as empty string it returns an image

image

from cloudinary_gem.

Mrodrides avatar Mrodrides commented on June 11, 2024

Ive done a couple of modifications to sort this issue:

image
Ive modified the resource_type method to accept a third argument
image
Also moved the guard clause in the ext_for_file method
image
It works for me but I dont know if I break any other uses of this gem

from cloudinary_gem.

d-mendoza avatar d-mendoza commented on June 11, 2024

If you open rails console in that project, what version do you get?

from cloudinary_gem.

Mrodrides avatar Mrodrides commented on June 11, 2024

It's 5.2.2

from cloudinary_gem.

d-mendoza avatar d-mendoza commented on June 11, 2024

My apologies, I meant to say, can you do this:

rails c
require 'cloudinary'
Cloudinary::VERSION

I just want to make sure the cloudinary version is right.

from cloudinary_gem.

Mrodrides avatar Mrodrides commented on June 11, 2024

image

from cloudinary_gem.

Mrodrides avatar Mrodrides commented on June 11, 2024

Ive been reviewing the code of active storage to check differences between 5.2 and 7.0

5.2 activestorage/app/controllers
image

Same folder in 7.0
image

Differences are massive, it is probably the cause of the issue.

from cloudinary_gem.

momoip avatar momoip commented on June 11, 2024

I'm checking internally and will keep you posted.

from cloudinary_gem.

momoip avatar momoip commented on June 11, 2024

I've opened an internal ticket for this issue and will keep you posted.

from cloudinary_gem.

Mrodrides avatar Mrodrides commented on June 11, 2024

Thank you @momoip

from cloudinary_gem.

momoip avatar momoip commented on June 11, 2024

@Mrodrides Of course. Will for sure let you know when the issue is fixed and deployed.

from cloudinary_gem.

tommyg-cld avatar tommyg-cld commented on June 11, 2024

@Mrodrides apologies for the delay, so we tested with csv files and cannot replicate on Rails 7.0.4
We got valid upload URLs and everything works as expected. We always saw the file content type detected right.

Are you still having this issue? If so, is it with specific CSV files and can you send us this file? Does upgrading to rails 7.0.4 help as well?

from cloudinary_gem.

Mrodrides avatar Mrodrides commented on June 11, 2024

Previously we had to vendorize the gem and modify it there but now we have upgraded raise and teared down all the internal hacks, so is back to normal.
Everything works correctly with the images and pdfs, but the raw files are still problematic, and worst of all the bugs are not consitent.

When for example i upload a csv, docx or a txt file, sometimes the url has the extension and sometimes it does not.
So when for example it is displayed in the app through the 'attachment.url(secure: true)' it leads to a 404, removing or adding .csv, .txt or .docx on the file solves the issue.

I have to remark here that we only use direct uploads.

On the other side, i notice that when in the console i do

image

As you can see, one has the format and the other not

from cloudinary_gem.

tommyg-cld avatar tommyg-cld commented on June 11, 2024

@Mrodrides thanks for getting back. How often are you seeing extensions not being included for raw files? Do you see any pattern in them? And is it happening on random raw files?

from cloudinary_gem.

const-cloudinary avatar const-cloudinary commented on June 11, 2024

@Mrodrides cloudinary_url() is a generic SDK function for building URLs.
For Active Storage integration please only use .url function. The difference between them is that it uses content type to identify file extension when needed (for raw files in this case).
Can you please provide an example of a csv/docx/txt file that leads to 404? so we can investigate it further?
Thank you!

from cloudinary_gem.

austenmadden avatar austenmadden commented on June 11, 2024

We were experiencing this same problem. We were on v1.23.0 and the fix included in v.1.24.0 found here resolved it.

from cloudinary_gem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.