首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActionDispatch::Http::UploadedFile for Active Storage 5.2

ActionDispatch::Http::UploadedFile for Active Storage 5.2
EN

Stack Overflow用户
提问于 2018-06-13 04:29:01
回答 1查看 888关注 0票数 0

我正在构建Rails API。并使用邮递员测试API。当通过邮递员上传文件时,我不会在后端得到文件数组。尽管我得到了ActionDispatch::Http::UploadedFile类型。正因为如此,我才不会在post_params中获得我的post_params。如何修复它。

这里是我的控制器类:

代码语言:javascript
复制
class Api::V1::PostsController < Api::V1::BaseController
  skip_before_action :authenticate, only: [:create]
  before_action :current_timeline, only: [:create]

  def create
    post = current_timeline.posts.build(post_params)
    binding.pry
    if post.save
      render_success(:created, post, meta: {message: 'Post sucessfully added'})
    else
      render_error(421, post.errors)
    end

  end

  private

  def post_params
    params.require(:post).permit(:message, :user_id, :occasion_id, :timeline_id, avatars: [])
  end

  def current_timeline
    Timeline.find(post_params[:timeline_id])
  end
end
EN

回答 1

Stack Overflow用户

发布于 2018-06-13 05:23:28

尽管我得到了ActionDispatch::Http::UploadedFile类型

在postman中,您需要将字段名更改为avatars[],然后可以将化身作为数组:

代码语言:javascript
复制
{"avatars"=>[#ActionDispatch::Http::UploadedFile....]}

您可以按照avatars[]发送带/不带索引的this answer参数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50829098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档