This repository has been archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add server endpoints for multipart upload and corresponding swagger api docs
- Loading branch information
1 parent
2d07777
commit 5e7b289
Showing
9 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
"""Uploader blueprints for various filetypes.""" | ||
from . import csv, nested_json, newick, d3_json # noqa: F401 | ||
from . import csv, nested_json, newick, d3_json, multipart_upload # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Multinet uploader for multi-part uploaded files.""" | ||
from base64 import b64encode | ||
|
||
from multinet import db, util | ||
|
||
from flasgger import swag_from | ||
from flask import Blueprint, request | ||
from webargs import fields | ||
from webargs.flaskparser import use_kwargs | ||
|
||
# Import types | ||
from typing import Any | ||
|
||
from multinet.errors import RequiredParamsMissing | ||
|
||
bp = Blueprint("uploads", __name__) | ||
bp.before_request(util.require_db) | ||
|
||
|
||
@bp.route("", methods=["POST"]) | ||
@swag_from("swagger/create_upload.yaml") | ||
def create_upload() -> str: | ||
"""Create a collection for multipart upload.""" | ||
return db.create_upload_collection() | ||
|
||
|
||
@bp.route("/<upload_id>/chunk", methods=["POST"]) | ||
@use_kwargs({"sequence": fields.Str(required=True)}) | ||
@swag_from("swagger/chunk_upload.yaml") | ||
def chunk_upload(upload_id: str, sequence: str) -> Any: | ||
"""Upload a chunk to the specified collection.""" | ||
chunk = dict(request.files).get("chunk") | ||
|
||
if chunk is None: | ||
raise RequiredParamsMissing(["chunk"]) | ||
|
||
# convert bytes to base64 string since arango doesn't support binary blobs | ||
stringified_blob = b64encode(chunk.read()).decode("ascii") | ||
|
||
db.insert_file_chunk(upload_id, sequence, stringified_blob) | ||
return sequence | ||
|
||
|
||
@bp.route("/<upload_id>", methods=["DELETE"]) | ||
@swag_from("swagger/delete_upload_collection.yaml") | ||
def delete_upload_collection(upload_id: str) -> Any: | ||
"""Delete the database collection associated with the given upload_id.""" | ||
return db.delete_upload_collection(upload_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Upload one chunk of data to the corresponding `uploads` document | ||
--- | ||
parameters: | ||
- $ref: "#/parameters/upload_id" | ||
- name: sequence | ||
in: query | ||
description: The sequence number of the multipart upload | ||
required: true | ||
schema: | ||
type: number | ||
example: 0 | ||
- name: chunk | ||
description: Raw file chunk data | ||
required: true | ||
in: formData | ||
type: file | ||
|
||
responses: | ||
200: | ||
description: The sequence number of the multipart upload | ||
schema: | ||
type: number | ||
example: 0 | ||
|
||
400: | ||
description: Missing required parameters | ||
schema: | ||
type: array | ||
items: | ||
type: string | ||
example: {"missing": ['chunk'] } | ||
|
||
404: | ||
description: Collection with specified `upload_id` does not exist | ||
schema: | ||
type: string | ||
example: u-1234abcd | ||
|
||
409: | ||
description: Document with specified sequence number already exists | ||
schema: | ||
type: number | ||
example: 0 | ||
|
||
tags: | ||
- uploads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Create a new collection in the `uploads` database for multipart upload storage | ||
--- | ||
responses: | ||
200: | ||
description: Unique ID for the collection that was created | ||
schema: | ||
type: string | ||
example: u-1234abcd | ||
|
||
tags: | ||
- uploads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Delete a multipart-upload collection from the database | ||
--- | ||
parameters: | ||
- $ref: "#/parameters/upload_id" | ||
responses: | ||
200: | ||
description: The `upload_id` of the deleted collection | ||
schema: | ||
type: string | ||
example: u-1234abcd | ||
|
||
404: | ||
description: Collection with ID of `upload_id` not found | ||
schema: | ||
type: string | ||
example: u-1234abcd | ||
|
||
tags: | ||
- uploads |