Search code examples
ruby-on-railsrubygoogle-cloud-storagecarrierwavefog

hostname "project-name.appspot.com.storage.googleapis.com" does not match the server certificate (OpenSSL::SSL::SSLError) - using fog and carriewave


I'm trying to implement image upload to google cloud storage from my rails 4.2 app using the carrierwave gem. Whenever I go to upload the image I get the error hostname "project-name.appspot.com.storage.googleapis.com" does not match the server certificate (OpenSSL::SSL::SSLError).

I cant see what I need to do from here.

carrierwave.rb file

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider:                         'Google',
    google_storage_access_key_id:     'key',
    google_storage_secret_access_key: 'secret key'
  }
  config.fog_directory = 'project-name.appspot.com'
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 what kind of storage to use for this uploader:
  #storage :file
   storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "check-item-value-images/#{model.id}"
  end

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like 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) do |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 worked fine before I implemented carrierwave for the image upload (would just save a string of the file name and not upload the image). Now that I've tried to implement carrierwave for image uploads I get the error above.

I used the carrierwave docs, this post, and this video by google cloud platform to get what I have now. What am I missing that is causing this error?


Solution

  • The issue is while using carrierwave you have dots (.) in your bucket.

    Create another bucket without dots and it will work.

    Here's some examples, seems your not the only one with this problem