CompleteMultipartUpload endpoint
https://redmine.teklia.com/issues/9153
Requires #1927 (closed)
A new CompleteMultipartUpload as a POST /api/v1/multipart/complete/ allows to complete a multipart upload after every part has been uploaded successfully. It uses a MultipartUploadCompleteSerializer that inherits from MultipartUploadSerializer and adds:
-
checksum_algorithm: optional, nullable EnumField accepting the names of the multipart upload checksum algorithms -
parts: A child serializer withmany=True-
part_number: required IntegerField, between 1 to 10000 -
checksum: optional, nullable CharField -
md5_hash: optional, nullable CharField -
etag: required CharField
-
The serializer's validate() method must verify that:
- when
checksum_algorithmis set,checksumis set on every part, or when it is not set,checksumis not set anywhere; - either all
md5_hashfields are set, or none are set; - all
part_numbervalues are unique.
If fields are inconsistently defined, an HTTP 400 error occurs.
The serializer's create() method must:
- call
object.s3_object.MultipartUpload(upload_id).complete()with thePartsbuilt from the part number, ETag and optional checksum of each part.- The
Partsmust be reordered by ascending part number. - The checksum must be base64-encoded.
- The
- call
object.s3_object.load(ChecksumMode="ENABLED")to verify the object exists and get its metadata- Note that
ChecksumModeis not documented inObject.load, but it exists: https://github.com/boto/boto3/issues/3498
- Note that
- handle
botocore.exceptions.ClientErrorexceptions, returning HTTP 400 or 404 with thee.response["Error"]["Message"]whene.response["Error"]["Code"] == "400"or"404" - verify that
object.sizeandobject.s3_object.content_lengthmatch - if everything went well:
- for a DataFile, update
statustoS3FileStatus.Checked - for a ModelVersion, update
statetoModelVersionState.Available
- for a DataFile, update
- if an error occurs or the sizes do not match:
- for a DataFile, update
statustoS3FileStatus.Error - for a ModelVersion, update
statetoModelVersionState.Error
- for a DataFile, update
The server-side checksum verification will be done at a later stage.
The API response should use DataFileSerializer or ModelVersionSerializer depending on the object type.