Answer the question
In order to leave comments, you need to log in
Amazon s3 + carrier wave. Problem uploading photos with resize enabled? How to decide?
Hello habra people. Help needed. Connected Amazon s3 file storage to carrierwave. Everything works until I include resize. When enabled, resize stops loading photos at all. what to do? I post the code:
class ImagesController < ApplicationController
before_action :set_image, only: [:show, :edit, :update, :destroy]
# GET /images
# GET /images.json
def index
@images = Image.all
end
# GET /images/1
# GET /images/1.json
def show
end
# GET /images/new
def new
@image = Image.new
end
# GET /images/1/edit
def edit
end
# POST /images
# POST /images.json
def create
@image = Image.new(images_params)
params[:image]['image'].each do |a|
Image.create(title: @image.title, image: a)
end
redirect_to root_path
end
# PATCH/PUT /images/1
# PATCH/PUT /images/1.json
def update
respond_to do |format|
if @image.update(image_params)
format.html { redirect_to @image, notice: 'Image was successfully updated.' }
format.json { render :show, status: :ok, location: @image }
else
format.html { render :edit }
format.json { render json: @image.errors, status: :unprocessable_entity }
end
end
end
# DELETE /images/1
# DELETE /images/1.json
def destroy
@image.destroy
respond_to do |format|
format.html { redirect_to images_url, notice: 'Image was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_image
@image = Image.find(params[:id])
end
def images_params
params.require(:image).permit(:title, :image)
end
end
# encoding: utf-8
class PictureUploader < 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
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fit => [50, 50]
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
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
= form_for @image, html: { multipart: true } do |f|
- if @image.errors.any?
#error_explanation
h2 = "#{pluralize(@image.errors.count, "error")} prohibited this image from being saved:"
ul
- @image.errors.full_messages.each do |message|
li = message
= f.text_field :title
= f.file_field :image, multiple: true
= f.submit
Answer the question
In order to leave comments, you need to log in
Are there any errors?
Most likely ImageMagick is not installed on the server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question