Exemple #1
0
def upload_complete_view(request: Request, upload_id: str) -> HttpResponseBase:
    """
    Complete a multipart upload.

    After all data has been uploaded using the URLs provided by initialize, this endpoint must
    be called to create the object in the object store. A presigned URL that performs the
    completion is returned, as the completion might take several minutes for large files.
    """
    request_serializer = UploadCompletionRequestSerializer(data=request.data)
    request_serializer.is_valid(raise_exception=True)
    parts: List[TransferredPart] = request_serializer.save()

    upload = get_object_or_404(Upload, upload_id=upload_id)

    completion = TransferredParts(
        object_key=upload.blob.name,
        upload_id=str(upload.multipart_upload_id),
        parts=parts,
    )

    completed_upload = MultipartManager.from_storage(AssetBlob.blob.field.storage).complete_upload(
        completion
    )

    response_serializer = UploadCompletionResponseSerializer(
        {
            'complete_url': completed_upload.complete_url,
            'body': completed_upload.body,
        }
    )
    return Response(response_serializer.data)
Exemple #2
0
    def initialize_multipart_upload(cls, etag, size):
        upload_id = uuid4()
        object_key = cls.object_key(upload_id)
        multipart_initialization = MultipartManager.from_storage(
            AssetBlob.blob.field.storage
        ).initialize_upload(object_key, size)

        upload = cls(
            upload_id=upload_id,
            blob=object_key,
            etag=etag,
            size=size,
            multipart_upload_id=multipart_initialization.upload_id,
        )

        return upload, {'upload_id': upload.upload_id, 'parts': multipart_initialization.parts}
Exemple #3
0
def multipart_manager(storage: Storage) -> MultipartManager:
    return MultipartManager.from_storage(storage)