我正在开发Reactjs
用作前端和Rails5 api only
应用程序作为后端的Web 应用程序
这是我发送到服务器的数据Request payload
------WebKitFormBoundaryCD1o71UpVNpU4v86
Content-Disposition: form-data; name="user[username]"
oeuoeoaeaoe
------WebKitFormBoundaryCD1o71UpVNpU4v86
Content-Disposition: form-data; name="user[profile_image]"; filename="gggg.jpg"
Content-Type: image/jpeg
------WebKitFormBoundaryCD1o71UpVNpU4v86--
这是我的控制器
def update_with_image
user = current_user
if user.update_attributes(user_update_params)
# Handle a successful update.
render json: user, status: 200
else
render json: { errors: user.errors }, status: 422
end
end
private
def user_update_params
params.require(:user).permit(:username,:profile_image)
end
因此,当我尝试将图像上传到 Rails 服务器时,出现此错误
ActionController::BadRequest (Invalid request parameters: invalid %-encoding ("user[username]"
oeuoeoaeaoe
------WebKitFormBoundaryCD1o71UpVNpU4v86
Content-Disposition: form-data; name="user[profile_image]"; filename="gggg.jpg"
Content-Type: image/jpeg
????JFIF????@6"??
??F!1AQ "aq?
#2???B?????$3Rb?%Cr?????? ??A!1A"Qaq?2???BR???#b??3rS?$Cs????
??%)):
rack (2.0.1) lib/rack/query_parser.rb:72:in `rescue in parse_nested_query'
rack (2.0.1) lib/rack/query_parser.rb:61:in `parse_nested_query'
** 我使用 Rack::Cors
andRack::Attack
作为我的中间件
我怎样才能解决这个问题?
谢谢!