airtasker/spot

Be able to describe a file upload endpoint

fwouts opened this issue · 4 comments

It's currently only possible to describe a JSON payload.

We'll cross that bridge when we get to it... It should be doable fairly easily with a new annotation.

Did you ever get around to implementing this? It's quite a common use-case for us.

Sorry Michiel, we didn't. Would you have a concrete example of such an endpoint? Is it strictly a file upload, or is it mixed with JSON e.g. with multipart/form-data?

It would be really great if we could describe multipart/form-data endpoints.

What I'm doing right now is this and it is not nearly ideal:

@endpoint()
class Endpoint {
  @request request(
    @headers
    _headers: {
      'Content-Type': 'multipart/form-data'
    },
    @body
    _body: {
      'source_file': { multipart: true }
    }
  ) {}
}

(The { multipart: true } body is there to keep me from accessing any info about the file the same way I would access JSON body data when using types generated from the spec. Otherwise it just serves the purpose of specifying the multipart body part/field name for the uploaded file.)


Based on the Swagger/OpenApi format, multipart bodies are described as the following:

requestBody:
  content: 
    multipart/form-data: # Media type
      schema:            # Request payload
        type: object
        properties:      # Request parts
          id:            # Part 1 (string value)
            type: string
            format: uuid
          address:       # Part2 (object)
            type: object
            properties:
              street:
                type: string
              city:
                type: string
          profileImage:  # Part 3 (an image)
            type: string
            format: binary

It should be possible to specify parts of different content types (such as JSON, binary, string).