ruby on rails - Using carrierwave to upload images to google cloud storage, the file name ends up being saved and not the public link to the image in the bucket -


i'm trying implement image upload google cloud storage rails 4.2 app using carrierwave gem. whenever go upload image uploaded bucket fine saved in db original image name e.g. image.png, not google cloud storage public link image e.g. https://storage.googleapis.com/project/bucket/image.png

not sure needed done here saving public link bucket , not file name.

carrierwave.rb file

carrierwave.configure |config|   config.fog_credentials = {     provider:                         'google',     google_storage_access_key_id:     'key',     google_storage_secret_access_key: 'secret key'   }   config.fog_directory = 'bucket-name' end 

uploaders/check_item_value_image_uploader.rb

class checkitemvalueimageuploader < carrierwave::uploader::base    # include rmagick or minimagick support:   # include carrierwave::rmagick   # include carrierwave::minimagick    # choose kind of storage use uploader:   #storage :file    storage :fog    # override directory uploaded files stored.   # sensible default uploaders meant mounted:   def store_dir     "check-item-value-images/#{model.id}"   end    # add white list of extensions allowed uploaded.   # images might use this:    def extension_white_list      %w(jpg jpeg gif png)    end  end 

related gems

gem 'gcloud' gem "fog" gem 'google-api-client', '~> 0.8.6' gem "mime-types" 

check_category_item_value model

mount_uploader :value, checkitemvalueimageuploader 

check_category_item_value update method

if @check_category_item_value.save     flash[:success] = "successfully updated"    redirect_to category_items_edit_path(@guide, @category, @category_item) else    render 'category_items/edit' end 

edit form

 <%= form_for(@check_category_item_value) |f| %>    <%= f.file_field :value, :value => item_key.value, accept: "image/jpeg, image/jpg, image/gif, image/png" %>    <%= f.submit "submit" %><hr>  <% end %> 

the forms works fine value saved original image name not google cloud storage public link image.

i used carrierwave docs, this post, , this video google cloud platform have now. missing?

update

adding config.fog_public = true nothing

carrierwave.configure |config|   config.fog_credentials = {     provider:                         'google',     google_storage_access_key_id:     'key',     google_storage_secret_access_key: 'secret key'   }   config.fog_public = true   config.fog_directory = 'bucket-name' end 

to set link public, please check config in config file:

# may set false config.fog_public = true 

for filename may overwrite in checkitemvalueimageuploader, here example:

class checkitemvalueimageuploader < carrierwave::uploader::base   def filename     "#{model.id}-#{original_filename}.#{file.extension}" if original_filename.present?   end end 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -