Search code examples
mulehttprequestanypoint-studioraml

Send multiple files in HTTP request using RAML


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


Solution

  • 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