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

Add a Cloudinary service for active_storage #341

Merged
merged 27 commits into from
Sep 11, 2019

Conversation

tocker
Copy link
Contributor

@tocker tocker commented Jul 14, 2019

Service tests are limited to Cloudinary use cases (i.e. storing images and not strings)

Service tests are limited to Cloudinary use cases (i.e. storing images and not strings)
@tocker tocker requested a review from itaibenari July 14, 2019 07:58
{
"Content-Type" => content_type,
"Content-MD5" => checksum,
# "Access-Control-Allow-Origin" => "localhost"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove if not necessary

end
else
instrument :download, key: key do
puts "download URL #{url}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use puts as a library owner. Hard to opt-out as a developer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging leftovers...

url = Cloudinary::Utils.unsigned_download_url(public_id(key), resource_type: resource_type(nil, key))
uri = URI(url)
instrument :download, key: key do
puts "download URL #{url}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use puts as a library owner. Hard to opt-out as a developer.


def api_uri(action, options)
base_url = Cloudinary::Utils.cloudinary_api_url(action, options)
cloudinary_params = Cloudinary::Uploader.build_upload_params(options)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename cloudinary_params to upload_params

instrument :download, key: key do
puts "download URL #{url}"
req = Net::HTTP::Get.new(uri)
req['range'] = "bytes=#{range.begin}-#{range.exclude_end? ? range.end - 1 : range.end}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice and future proof to consider endless ranges (ruby 2.6)
https://rubyreferences.github.io/rubychanges/2.6.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

def upload(key, io, filename: nil, checksum: nil, **options)
instrument :upload, key: key, checksum: checksum do
begin
extra_headers = checksum.nil? ? {} : {'Content-md5': checksum}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content-md5 has different casing then in headers_for_direct_upload . Consider a constant maybe ?

begin
extra_headers = checksum.nil? ? {} : {'Content-md5': checksum}
options = @options.merge(options)
@image_meta = Cloudinary::Uploader.upload(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is @image_meta being used ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No... will remove

@edoshor
Copy link

edoshor commented Jul 15, 2019

What about large files? is that supported at our sdk level ?

AS_TAG = "active_storage_" + SUFFIX

SERVICE = ActiveStorage::Service.configure(:cloudinary, SERVICE_CONFIGURATIONS)
CONFIGURATION_PATH = Pathname.new(File.expand_path("service/configurations.yml", __dir__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants will be available globally (in testing) because they're defined here. Maybe they should be namespaced inside the describe block.

end

it "should support uploading to Cloudinary" do
begin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

**options
)
rescue CloudinaryException
raise ActiveStorage::IntegrityError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to add a message or wrap the CloudinaryException or at least pass on the backtrace?

@amcaplan amcaplan force-pushed the feature/support-active-storage branch from 0810d04 to b947a96 Compare August 27, 2019 16:47
Ariel Caplan and others added 5 commits August 27, 2019 19:48
Order of dependencies loading apparently makes a big difference, and
sprockets isn't helping here.

We know this used to work, and the relevant code wasn't changed, so
hopefully this just works now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants