Send multiple files in HTTP request using RAML

与世无争的帅哥 提交于 2019-12-13 04:33:39

问题


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?

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

Thanks


回答1:


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

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

Here , we use type abstraction to define a type and then use it as a array along with multipart/form-data



来源:https://stackoverflow.com/questions/46767235/send-multiple-files-in-http-request-using-raml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!