PUT 요청을 통해 내 서버에 REST API를 사용하여 첨부 파일을 업로드하려고합니다. 요청 본문에 바이너리 파일을 저장하여이 작업을 수행 할 수 있지만이 파일을 첨부 파일을 저장하는 클립 클립을 사용하는 모델의 첨부 파일로 저장하려고합니다.Ruby on Rails : REST API + 파일 업로드 + 클립
여기에 내 현재 관련 클래스 정의를 다음과 같습니다
class Cl < ActiveRecord::Base
after_update :save_tses
validates_associated :tses
has_many :tses
...truncated...
def save_tses
tses.each do |ts|
ts.save(false)
end
end
end
class Ts < ActiveRecord::Base
has_attached_file :tsa, :styles => { :thumb => {:geometry => "100x141>", :format => :jpg} },
:path => ":rails_root/public/system/:attachment/:id/:style/:friendly_filename",
:url => "/system/:attachment/:id/:style/:friendly_filename"
belongs_to :cl
def friendly_filename
"#{self.tsa_file_name.gsub(/[^a-zA-Z0-9_\.]/, '_')}"
end
end
나는 잘 HTML 페이지에서 파일 업로드를 사용하여 첨부 파일을 저장할 수 있습니다. PUT 요청을 통해 이진 데이터로 파일을받는 컨트롤러에서이 작업을 수행하고 싶습니다.
제안 사항?