Skip to content

Rails quickstart fails with invalid URL #8

Description

@titusjohnson

Following the readme for Shrine and Shrine-Cloudinary to get some simple image uploads going fails with Cloudinary producing an invalid URL when attempting to move the image from cache to storage.

require "shrine"
require "cloudinary"
require "shrine/storage/cloudinary"

Cloudinary.config(
  cloud_name: ENV.fetch('CLOUDINARY_NAME'),
  api_key:    ENV.fetch('CLOUDINARY_API_KEY'),
  api_secret: ENV.fetch('CLOUDINARY_API_SECRET'),
)

Shrine.storages = {
  cache: Shrine::Storage::Cloudinary.new(prefix: "dev/cashe"),
  store: Shrine::Storage::Cloudinary.new(prefix: "dev/site"),
}

Shrine.plugin :activerecord           # loads Active Record integration
Shrine.plugin :cached_attachment_data # enables retaining cached file across form redisplays
Shrine.plugin :restore_cached_data    # extracts metadata for assigned cached files

Form:

= form_for @photo, url: location_photos_path(@location) do |f|
  = f.hidden_field :image, value: @photo.cached_image_data
  %p
    = f.label :image, 'Select Image'
    = f.file_field :image
  %p
    = f.label :primary do
      = f.check_box :primary
      Primary? (shown first)
  = f.submit

Error:

CloudinaryException in PhotosController#create
Error in loading https:///image/upload/v1/dev/cashe/307b71836c1af10884968e59aa325add.jpg - Invalid URI

Stacktrace:

cloudinary (1.13.2) lib/cloudinary/uploader.rb:342:in `block in call_api'
rest-client (2.1.0) lib/restclient/request.rb:834:in `process_result'
rest-client (2.1.0) lib/restclient/request.rb:743:in `block in transmit'
/Users/titusjohnson/.rbenv/versions/2.6.3/lib/ruby/2.6.0/net/http.rb:920:in `start'
rest-client (2.1.0) lib/restclient/request.rb:727:in `transmit'
rest-client (2.1.0) lib/restclient/request.rb:163:in `execute'
rest-client (2.1.0) lib/restclient/request.rb:63:in `execute'
cloudinary (1.13.2) lib/cloudinary/uploader.rb:329:in `call_api'
cloudinary (1.13.2) lib/cloudinary/uploader.rb:76:in `upload'
shrine-cloudinary (1.1.1) lib/shrine/storage/cloudinary.rb:181:in `public_send'
shrine-cloudinary (1.1.1) lib/shrine/storage/cloudinary.rb:181:in `method_missing'
shrine-cloudinary (1.1.1) lib/shrine/storage/cloudinary.rb:96:in `store'
shrine-cloudinary (1.1.1) lib/shrine/storage/cloudinary.rb:24:in `upload'
shrine (3.2.1) lib/shrine.rb:245:in `_upload'
shrine (3.2.1) lib/shrine.rb:210:in `upload'
shrine (3.2.1) lib/shrine.rb:108:in `upload'
shrine (3.2.1) lib/shrine/attacher.rb:182:in `upload'
shrine (3.2.1) lib/shrine/attacher.rb:171:in `promote'
shrine (3.2.1) lib/shrine/attacher.rb:162:in `promote_cached'
shrine (3.2.1) lib/shrine/attacher.rb:145:in `finalize'
shrine (3.2.1) lib/shrine/plugins/activerecord.rb:90:in `activerecord_after_save'
...(snip)

Note the lack of a cloudinary domain name in the temp file URI. The temp files do appear on Cloudinary, I can see & manipulate them via the UI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions