使用RAML在HTTP请求中发送多个文件

问题描述:

我正在使用RAML编写HTTP POST请求,并且需要编写它才能发送请求中的多个文件.每次文件的数量可能不同,因此需要动态.我该怎么做?

I am writing an HTTP POST request using RAML and need to write it to be able to send multiple files in the request. The number of files might be different each time so need it to be dynamic. How do I do this?

这最终将与Anypoint Studio 6.2和Mule 3.8.3一起使用

This will eventually be used with Anypoint Studio 6.2 and Mule 3.8.3

谢谢

如果您使用的是 RAML版本0.8 ,请尝试以下构造.它具有 repeat 属性,该属性指定可以多次上传

If you are using RAML version 0.8, try below construct.It is having repeat property which specify possiblilty of multiple uploads

#%RAML 0.8
title: FileUploadExample
baseUri: localhost
/uploadMultipleFile:
  description: Uploads Multiple file 
  post:
    body:
        multipart/form-data:
         formParameters:
             file:
               description: The file to be uploaded. Supported Formats are gif, jpeg, jpg, png etc.
               required: true
               type: file
               repeat: true

如果您使用的是 RAML 1.0版 由于 repeat 位于 RAML 0.8规范之内,因此在RAML 1.0中已将其删除,以支持RAML数据类型抽象. 因此,对于RAML 1.0,您可以使用类似于下面的构造.

If you are using RAML version 1.0 Since repeat is inside the RAML 0.8 specification ,it is removed in RAML 1.0 in favour for RAML data types abstraction. So for RAML 1.0 ,you can use something similar to below construct.

#%RAML 1.0
title: FileUploadExample
baseUri: localhost
types:
  MultiUploadFileType:
       properties:
          file:
            description: The file to be uploaded. Supported Formats are gif, jpeg, jpg, png etc.
            required: true
            type: file

/uploadMultipleFile:
  description: Uploads Multiple file
  post:
    body:
      multipart/form-data:
        type: MultiUploadFileType[]
        minItems: 1

在这里,我们使用类型抽象来定义类型,然后将其与multipart/form-data一起用作数组