当我通过 POST 查询到 API 使用 form_tag 进行文件上传时,我遇到了麻烦。当我使用:
= form_tag("http://myapi.com/api/images/user/#{@user_id}", multipart: true) do
= file_field_tag 'upload'
= submit_tag 'Upload avatar'
我没有烦恼。但是当我尝试使用 update_avatar 的操作时,我遇到了麻烦。
= form_tag({:action => 'upload_avatar'}, multipart: true) do
= file_field_tag 'upload'
= submit_tag 'Upload avatar'
update_avatar 动作代码:
def upload_avatar
@user_id = params[:id]
@post_params = {'upload' => params[:upload]}
response, data = Net::HTTP.post_form(URI.parse("http://myapi.com/api/images/user/#{@user_id}"), @post_params)
redirect_to users_path
end
回应是:
#<Net::HTTPInternalServerError:0x007f331486f4e0>
数据为:无