6
클립을 사용하여 모델에 파일을 추가합니다.Paperclip 및 xhr.sendAsBinary
firefox 3.6의 새로운 기능인 xhr.sendAsBinary
을 사용하여 ajax 요청과 함께 파일을 보내고 싶습니다.
var xhr = new XMLHttpRequest();
xhr.open("POST", "/photos?authenticity_token=" + token
+ "&photo[name]=" + img.name
+ "&photo[size]=" + img.size);
xhr.overrideMimeType('text/plain; charset=x-user-defined-binary');
xhr.sendAsBinary(bin);
name
및 size
가 문제없이 내 모델에 저장되지만 파일 자체가 클립에 의해 사로 잡았되지 않은 : 여기
는 내 요청을 구축하는 방법이다.
내 모델
class Photo < ActiveRecord::Base
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
마이그레이션
def self.up
add_column :photos, :photo_file_name, :string
add_column :photos, :photo_content_type, :string
add_column :photos, :photo_file_size, :integer
add_column :photos, :photo_updated_at, :datetime
end
내 컨트롤러 방법이 문제를 해결하는
# POST /photos
# POST /photos.xml
def create
@photo = Photo.new(params[:photo])
respond_to do |format|
if @photo.save
format.html { redirect_to(@photo, :notice => 'Photo was successfully created.') }
format.xml { render :xml => @photo, :status => :created, :location => @photo }
else
format.html { render :action => "new" }
format.xml { render :xml => @photo.errors, :status => :unprocessable_entity }
end
end
end
어떤 생각?
감사합니다.
로 파일을 처리하는이
처럼 보인다? –
여기 있습니다, 고마워요. – denisjacquemin