I have successfully implemented image uploading using carrierwave, fog and Amazon S3. In my imageuploader am using only fog as storage. But when i check my database i can see that just the file name is written instead of the amazon url. In my views its fetching correctly from aws without any issues.
Is it supposed to be like this?
If so how the application figure out the exact url to s3?
imageuploader.rb`
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
include CarrierWave::MiniMagick
#Include the sprockets-rails helper for Rails 4+ compatibility:
include Sprockets::Rails::Helper
storage :fog
version :index_size do
process :resize_to_fill => [258, 173]
end
version :thumb_size do
process :resize_to_fill => [100, 100]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
Your config has the bucket name and the database has the filename. These are the only two pieces of information that are actually required to construct a filename (and it can be done without other API calls). The urls are actually pretty regular, so it is fairly straightforward for the server to do this. Hope that helps!
Related
I am using Carrierwave to upload images and that works fine but I am now trying to use Minimagick to process these uploaded images.
What is going on?
The images still upload as well as their thumb version, however both images are exactly the same size.
Here is the uploader code:
class FileUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# Override the directory where uploaded files will be stored.
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fit => [100, 100]
end
# Add a white list of extensions which are allowed to be uploaded.
def extension_white_list
%w(jpg jpeg gif png)
end
end
And here is how I am calling it:
<%= image_tag example.my_file.url(:thumb).to_s %>
I dont think it is anything to do with the way I am calling it because the two files created by all this are the same, so sound slike its to do with processing it on upload.
Here is the folder created for each object:
Image
--- Fixed ---
The issue was ImageMagick. It was not properly configured on my machine so that means no gem that deals with image processing (Paperclip, Minimagick or Dragonfly) could complete any image manipulation.
I want to upload a zip file contains documents and after uploading it to server I want to extract those on server.
I have used Carrierwave Gem to upload zip file code is below for that :
class AttachmentUploader < 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
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(zip)
#%w(pdf doc htm html docx)
end
end
No what I want to know that which Gem can help me to achieve the extraction part and where that code will be placed in this uploader class or anywhere else.. I'm very new to this rails stuff so if this question require anything more pls do let me know.
I'm having performance issues with carrierwave uploads on images using Rackspace. There have been no other reasons or bugs that would identify what the issue is, and a quick test deploy using S3 solves the issues completely.
Is there any way to maintain the rackspace links and images when making the change to s3? When we change them on a staging server all url references are removed and replaced with the new url, making all images go 404.
class PostimageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# These settings are for image updloads to rackspace
if Rails.env.production?
storage :fog
else
storage :file
end
# Do not edit this file structure
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
Thanks for any help.
I am trying to implement image-upload with CarrierWave and MiniMagick. I was able to upload an image with carrierwave, but when I implemented MiniMagick to resize uploaded images, it returned this error:
Errno::ENOENT in ItemsController#create
No such file or directory - identify -ping /var/folders/6y/j8zfcgmd02x5s439c0np8fjh0000gn/T/mini_magick20121228-71203-bdoeul.jpg
image_uploader.rb
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_fill => [100, 100]
end
end
I have imagemagick installed.
Not sure what went wrong, but after I uninstalled MacPort and all its ports, installed Homebrew and reinstalled ImageMagick, everything works as expected.
I'm creating a Rails 3 Application that uses Carrierwave & Amazon S3. The Problem that I'm running into is that when Carrierwave uploads images to Amazon it's setting the Content-Type to Application/Octet-Stream instead of it's actual content type.
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
process :resize_to_limit => [100, 75]
process :convert => 'png'
end
From https://github.com/jnicklas/carrierwave/issues/284#issuecomment-1925631:
Add require 'carrierwave/processing/mime_types' to an initializer or your uploader(s).
Add include CarrierWave::MimeTypes to your uploader.
Add process :set_content_type to your uploader(s).