안녕하세요 저는 웹 응용 프로그램 I을 개발 중이며 사용자에게 프로필 사진을 업로드 할 수있는 기회를 제공하려고합니다. 나는 carrierwave와 s3를 사용하는 안개를 얻으려고 많은 시간을 보냈지 만 그것을 달성하지 못했습니다. 네가 나에게 줄 수있는 어떤 도움이라도별로 감탄하지 않는다.레일 이미지 캐리어 웨이브 및 안개가있는 S3로 업로드
업데이트 : 업데이트 : 필자는 계속 파일을 만들려고 노력하고 파일에서 결코 uplaoding을하지 못한다고 말하면 : 이미지 값은 항상 사용자 컨트롤러에서 비어 있습니다.
내 업 로더 클래스입니다.
class PhotoUploader < CarrierWave::Uploader::Base
storage :fog
def store_dir
"uploads/#images/#{model.class.to_s.underscore}"
end
end
안개 이니셜
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'xxx',
:aws_secret_access_key => 'yyy',
}
config.fog_directory = 'pictures_dev'
config.fog_public = true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
사용자 모델
class User
include Mongoid::Document
....
has_one :photo
....
end
사진 모델
class Photo
include Mongoid::Document
attr_accessible :name, :image
field :image, :type => String
field :name, :type => String
belongs_to :user
mount_uploader :image, PhotoUploader
end
사진 컨트롤러
누군가가 내가 드리겠습니다 더 많은 코드를 게시하려면 내가 필요하면class PhotoController < ApplicationController
def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(params[:image])
flash[:success] = "Your have updated your settings successfully."
else
flash[:error] = "Sorry! We are unable to update your settings. Please check your fields and try again."
end
redirect_to(:back)
end
업로드 양식
= form_for @photo, :html => {:multipart => true} do |f|
%p
%label Photo
= image_tag(@user.image_url) if @photo.image?
= f.file_field :image
= f.submit
이 내가 그 생각할 수있는 전부이다는 관련이 있습니다. 솔직히 말하면 도움을 청합니다.
로그에 오류가 있습니까? –
S3 버킷을 잘못된 지역에 두었을 수 있습니까? –
Christopher, S3 버킷이 정확한 위치에 있습니다. 카일. 오류는 전혀 없어. 이미지는 절대 업로드되지 않습니다. – EnriqueC