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

Cloudinary direct upload bypassing rails app #117

Closed
jlerpscher opened this issue Jun 18, 2014 · 5 comments
Closed

Cloudinary direct upload bypassing rails app #117

jlerpscher opened this issue Jun 18, 2014 · 5 comments

Kommentare

@jlerpscher
Copy link

Hi,

I am trying to upload directly to Cloudinary, bypassing my rails app. I am working with Carrierwave and a Picture Uploader .

class PictureUploader < CarrierWave::Uploader::Base
  include Cloudinary::CarrierWave

  eager
  make_private

  version :tiny do
    resize_to_fill(100, 100)
  end

  version :full do
    cloudinary_transformation transformation: [
      { width: 1500, height: 1200, crop: :limit, quality: 80, flags: 'progressive' }
    ]
  end
= cl_form_tag my_callback_url, form: { class: 'fileupload' }, type: :private do
  = file_field_tag :file
  = submit_tag 'Upload'

Until now, everything is fine. But in my controller, I am unable to save the picture path unless doing the following:

@car = current_user.cars.build
path = "#{params[:resource_type]}/#{params[:type]}/v#{params[:version]}/#{params[:public_id]}"
path += ".#{params[:format]}" if params[:format].present?
path += "##{params[:signature]}"
@car.picture = path
# here path eq "image/private/v14030428xxx/lez0juhg5d5owvnsxxx.jpg#xxxxxx729ef01301xxx2e3171d316e0805c2xxx"
@car.save!

I guess it's not the cleanest way to do that.

I have tried to build directly with params but it did not save.
I also tried with cloudinary_url but it also failed. The result looks like:

"http://res.cloudinary.com/hd0w8otcz/image/private/v140304xxxx/lez0juhg5d5owxxxxxxx.jpg"

The params are:

{"bytes"=>"73526",
 "created_at"=>"2014-06-17T22:07:23Z",
 "etag"=>"43e4702e787fc96b2920a939efcaxxxx",
 "format"=>"jpg",
 "height"=>"606",
 "public_id"=>"lez0juhg5d5owvnszljo",
 "resource_type"=>"image",
 "signature"=>"xxxxxx729ef01301xxx2e3171d316e0805c2xxx",
 "type"=>"private",
 "version"=>"1403042843",
 "width"=>"808"}

So, what is the best way to upload to cloudinary bypassing my rails app?

@taragano
Copy link
Collaborator

When using Direct upload with CarrierWave, the library automatically takes the image's details and stores it as the identifier. You can have a look at the Sample project which demonstrates both server-side and client-side uploads, including CarrierWave integration.
https://github.com/cloudinary/cloudinary_gem/tree/master/samples/photo_album

@jlerpscher
Copy link
Author

Thank you for your answer.

The solution provided in the sample app require javascript. I am looking for a solution without any javascript.

@taragano
Copy link
Collaborator

If you want to convert an upload response to something CarrierWave will be willing to accept, you can use:

Cloudinary::Utils.signed_preloaded_image(params)

@jlerpscher
Copy link
Author

Hi,

Sorry, back from holidays.

Cloudinary::Utils.signed_preloaded_image(params)

doesn't seems handle private upload, I need something like:

"image/private/v1404760155/aaar1lttbgujqhdaaa.jpg#aaaaaab0b57be13297c6bb0a790e309"

but I get something like that:

"image/upload/v1404760287/cwuqrownwmqxl3pay4de.jpg#8cf120c91bb36a8e8a136170b6a8e28431bcdc18"
"#{result["resource_type"]}/upload/v#{result["version"]}/#{[result["public_id"], result["format"]].reject(&:blank?).join(".")}##{result["signature"]}"

params type it is not used in the function. Am I missing something?

@jlerpscher
Copy link
Author

works great! Thank you.

nadavs added a commit that referenced this issue Jul 14, 2014
…d update. Support coordinates in resource details. Support delete_by_token for direct uploads. Support shorthand blank for cl_image_tag with responsive/hidpi. Correctly encode one-level double arrays. Support non-upload resources in signed_preloaded_image (Issue #117). Support background removal upload and admin API parameter. Update Cloudinary's jQuery plugin to v1.0.19.
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

No branches or pull requests

2 participants