Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow UPLOADCARE_CDN_BASE setting. #24

Closed
boxmo opened this issue Apr 24, 2015 · 14 comments
Closed

Allow UPLOADCARE_CDN_BASE setting. #24

boxmo opened this issue Apr 24, 2015 · 14 comments
Assignees

Comments

@boxmo
Copy link

boxmo commented Apr 24, 2015

There's a way that i can load images on https protocol?

@dmitry-mukhin
Copy link
Member

yup, just replace whatever CDN prefix you have with https://ucarecdn.com
Widget has a setting for it: https://uploadcare.com/documentation/widget/#option-cdn-base

@boxmo
Copy link
Author

boxmo commented Apr 24, 2015

@dmitry-mukhin why this isn't an option on uploadcare.yml file?

@dmitry-mukhin
Copy link
Member

gem is bit outdated.
you can send a PR that will add this setting to a widget renderer.

@dmitry-mukhin dmitry-mukhin reopened this Apr 24, 2015
@dmitry-mukhin dmitry-mukhin changed the title cdn_url with https protocol Allow UPLOADCARE_CDN_BASE setting. Apr 24, 2015
@djalmaaraujo
Copy link

👍 really needed

@Oshuma
Copy link

Oshuma commented Jun 19, 2018

Is this still a planned enhancement or is there a known workaround?

@dmitry-mukhin
Copy link
Member

@Oshuma you can always add this setting (along with any other) to your HTML or templates manually without gem's help.

Does it make sense?

@Oshuma
Copy link

Oshuma commented Jun 19, 2018

@dmitry-mukhin I can add the setting manually to templates, and it does use the CDN URL when saving to the model attribute, however any subsequent methods that use the model's has_uploadcare_file field doesn't use the CDN URL; i.e. #to_s and #url still use the base CDN URL. For example:

// Widget setting:
UPLOADCARE_CDN_BASE = "https://ucarecdn.example.com";
# Image model:
#   has_uploadcare_file :uploadcare

image = Image.last
# In the database, the field is saved using the correct CDN URL:
# uploadcare: "https://ucarecdn.example.com/e379b8b7-178a-4fb5-8729-e1bfec0b1a7e/"

# However, using #to_s or #url returns the standard UC CDN:
image.uploadcare.url
# => "https://ucarecdn.com/e379b8b7-178a-4fb5-8729-e1bfec0b1a7e/"
image.uploadcare.to_s
# => "https://ucarecdn.com/e379b8b7-178a-4fb5-8729-e1bfec0b1a7e/"
image.uploadcare.url(inline: "/scale_crop/80x80/center")
# => "https://ucarecdn.com/e379b8b7-178a-4fb5-8729-e1bfec0b1a7e/-/scale_crop/80x80/center/"

@Oshuma
Copy link

Oshuma commented Jun 19, 2018

So a workaround that I think is working is setting static_url_base in the uploadcare.yml config. When that set, the methods are now using the correct CDN domain, even for images which have the base UploadCare CDN domain stored in the column.

# ./config/uploadcare.yml
cdn_base: "https://ucarecdn.example.com"
static_url_base: "https://ucarecdn.example.com"
[1] pry(main)> image = Image.first
=> # uploadcare: "https://ucarecdn.com/170f0b2d-4e1a-4997-8e22-4f4600cd9ca1/"
[2] pry(main)> image.uploadcare.to_s
=> "https://ucarecdn.example.com/170f0b2d-4e1a-4997-8e22-4f4600cd9ca1/"
[3] pry(main)> image.uploadcare.url(inline: "/scale_crop/80x80/center")
=> "https://ucarecdn.example.com/170f0b2d-4e1a-4997-8e22-4f4600cd9ca1/-/scale_crop/80x80/center/"

@Oshuma
Copy link

Oshuma commented Jun 20, 2018

@dmitry-mukhin Are you aware of any side effects of that ^ workaround (setting the static_url_base as our CDN domain). I found that while looking through the library's code, but don't see it documented anywhere.

@dmitry-mukhin
Copy link
Member

@Oshuma I'd say that you're safe to use that hack.
@vizvamitra can you please confirm this?

@Oshuma
Copy link

Oshuma commented Jun 26, 2018

@dmitry-mukhin I've made that change in our production app and have it deployed. It seemed to do the trick. All images are successfully getting uploaded and served through our CDN.

@dmitry-mukhin
Copy link
Member

👍
pull requests are most welcome

@Oshuma
Copy link

Oshuma commented Jun 26, 2018

I actually didn't have to change any code in the library, only added that static_url_base value in the config file. The code already uses that value when building the URL.

https://github.com/uploadcare/uploadcare-ruby/blob/51fab41f46619720a1ceb590a6953643f9bc0395/lib/uploadcare/resources/file.rb#L28-L30

@dmitrijivanchenko
Copy link
Contributor

dmitrijivanchenko commented Oct 13, 2021

@boxmo, Hi, we released a new v2 version of the gem. You can set this param in the initializer in v2 (uploadcare.rb). Please, see https://github.com/uploadcare/uploadcare-rails#readme in the main branch for more info.

@rsedykh rsedykh closed this as completed Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants