Javascript 无法找到或生成blob:应为可附加,已获取(<;ActionController::允许的参数{}:false>;

Javascript 无法找到或生成blob:应为可附加,已获取(<;ActionController::允许的参数{}:false>;,javascript,ruby-on-rails,reactjs,image,file,Javascript,Ruby On Rails,Reactjs,Image,File,我很难从react前端向RubyonRails后端发送1个图像 以下是步骤 反应中(前端) 从输入中获取图像作为“e.target.files[0]”,并将其保存在变量中。然后,将其传递给UpdateNouser 发送用户信息以及id和他的图像(化身)。imageInfo有e.target.files[0] RubyonRails(后端) 后端中的端点接收并将其传递给def update 然后,我在@user.avatar.attach(params[:image])行上收到错误。上面说是空的

我很难从react前端向RubyonRails后端发送1个图像

以下是步骤

反应中(前端)

  • 从输入中获取图像作为“e.target.files[0]”,并将其保存在变量中。然后,将其传递给UpdateNouser
  • 发送用户信息以及id和他的图像(化身)。imageInfo有e.target.files[0]
  • RubyonRails(后端)

  • 后端中的端点接收并将其传递给def update
  • 然后,我在@user.avatar.attach(params[:image])行上收到错误。上面说是空的
  • 为什么这样说?我将带有append的formdata图像发送到后端,但不知怎的,我无法在后端访问它。 在模型中,它有一个附件:阿凡达 在Gemfile中,它有gem'activestoragevalidator'

    我真的很感激任何帮助

    export const updateOneUser = async (id, data, imageInfo) => {
    
        const formData = new FormData();
        formData.append('image', imageInfo)
    
        const resp = await api.put(`/users/${id}`, { user: data, image: formData });
        return resp.data;
    }
    
    def update
    
            @user = User.find(params[:id])         
            if @user.update(user_params)  #update in Schema
        
            @user.avatar.destroy  if @user.avatar.present?  # Active Storage
            @user.avatar.attach(params[:image]) # Active Storage
    
          render json: @user
        else
          render json: @user.errors, status: :unprocessable_entity
        end
    
      end