Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support uploading and downloading files #27

Open
zdd248 opened this issue Dec 12, 2018 · 1 comment
Open

Support uploading and downloading files #27

zdd248 opened this issue Dec 12, 2018 · 1 comment
Labels
good first issue Good for newcomers

Comments

@zdd248
Copy link

zdd248 commented Dec 12, 2018

EXAMPLE:

val upload = post |>
  operation('download) |>
  formField[(FileInfo, Source[ByteString, Any])]('file) |>
  $$[String]
val download = get |>
  operation(Symbol("download")) |>
  $$[File]

AKKA HTTP DOCUMENTATION:

fileUpload
https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/file-upload-directives/fileUpload.html

getFromFile
https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/file-and-resource-directives/getFromFile.html

@zdd248
Copy link
Author

zdd248 commented Dec 13, 2018

Swagger 3.0 specification for file upload
https://swagger.io/docs/specification/describing-request-body/file-upload/

ONE FILE

Swagger:

requestBody:
  content:
    multipart/form-data:
      schema:
        type: object
        properties:
          orderId:
            type: integer
          userId:
            type: integer
          fileName:
            type: string
            format: binary

Http Request:

POST /upload
Host: example.com
Content-Length: 2740
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryWfPNVh4wuWBlyEyQ
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="orderId"
1195
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="userId"
545
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fileName"; filename="attachment.txt"
Content-Type: text/plain
[file content goes there]
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ

ARRAY FILE

Swagger:

requestBody:
  content:
    multipart/form-data:
      schema:
        type: object
        properties:
          filename:
            type: array
            items:
              type: string
              format: binary

Http Request:

POST /upload
Host: example.com
Content-Length: 2740
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryWfPNVh4wuWBlyEyQ
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fileName"; filename="file1.txt"
Content-Type: text/plain
[file content goes there]
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fileName"; filename="file2.png"
Content-Type: image/png
[file content goes there]
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fileName"; filename="file3.jpg"
Content-Type: image/jpeg
[file content goes there]
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ

@Odomontois Odomontois added the good first issue Good for newcomers label Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants