简体   繁体   English

Rails-不允许通过Postman Params发送数组

[英]Rails - Sending array through Postman Params not permitted

Im trying to upload images in rails using Carrierwave. 我正在尝试使用Carrierwave在轨中上传图像。 but I'm having a problem in permissions 但是我的权限有问题

This is my controller: 这是我的控制器:

class PhotoController < ApplicationController
  def upload_multiple
    render json: {
      status: params[:photos].inspect,
    }, status: 200
  end

  def photos_params
    params.require(:photos).permit(:photos => [])
  end
end

Im trying to inspect to debug. 我试图检查调试。 The result of inspect is: 检查的结果是:

"status": "<ActionController::Parameters {\"1\"=>#<ActionDispatch::Http::UploadedFile:0x00007fe8b1ae7d50 @tempfile=#<Tempfile:/var/folders/4w/32p7h9rx2mjf9_m60852pn2m0000gn/T/RackMultipart20190406-1520-1r799qx.jpg>, @original_filename=\"IMG_1303.jpg\", @content_type=\"image/jpeg\", @headers=\"Content-Disposition: form-data; name=\\\"photos[1]\\\"; filename=\\\"IMG_1303.jpg\\\"\\r\\nContent-Type: image/jpeg\\r\\n\">} permitted: false>"

What Im passing in postman is as follows: 我在邮递员中传递的内容如下: 在此处输入图片说明

What am I doing wrong? 我究竟做错了什么?

EDIT 编辑

Rename the parameter from photos[1] to photos[] . 将参数从photos[1]重命名为photos[] I can't say is this possible in postman, but in terms of html it should be <input type="file" name="photos[]"> (and the form enctype is multipart/form-data ), since it's looks like you're sending a hash, then change params.require(:photos).permit(:photos => []) to params.permit(photos: []) . 我不能说这在邮递员中是可能的,但是就html而言,它应该是<input type="file" name="photos[]"> (并且表单enctypemultipart/form-data ),因为它看起来就像您发送哈希一样,然后将params.require(:photos).permit(:photos => [])更改为params.permit(photos: [])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM