我需要实现文件上传使用葡萄UI。我们有这些宝石:
gem 'grape'
gem 'grape-entity'
gem 'grape-papertrail'
gem 'grape-swagger'
gem 'grape-swagger-entity'在我的attachments_api.rb里
# frozen_string_literal: true
module V1
class AttachmentsAPI < ApplicationAPI
content_type :pdf, 'multipart/form-data'
resource :attachments do
desc 'Upload attchment file'
params do
requires :file, type: File, documentation: { param_type: 'formData', data_type: 'file' }
end
post do
byebug
end
end
end
end但是,当我在UI (https://editor.swagger.io/)中运行它时,每次都会收到相同的错误(我尝试附加txt文件,png或pdf并不重要):
The requested format 'txt' is not supported.更奇怪的外观生成了json_doc:
paths:
/attachments:
post:
description: Upload attchment file
produces:
- application/json
consumes:
- application/json
parameters:
- in: formData
name: file
type: file
required: true
responses:
'201':
description: Upload attchment file
tags:
- attachments
operationId: postAttachments我不明白为什么我们看到那里
consumes:
- application/json如何修复此错误并进行适当的文件上传?谢谢你的帮助!
发布于 2020-09-05 02:38:37
这解决了问题:
desc 'Upload attachment file', consumes: ['multipart/form-data']https://stackoverflow.com/questions/63736815
复制相似问题