Fix image API for V2 images
This commit is contained in:
parent
bc4e07343e
commit
dead054b43
2 changed files with 13 additions and 16 deletions
|
@ -109,8 +109,8 @@ def download_blob(namespace, repo_name, digest):
|
|||
return Response(storage.stream_read(found.locations, path), headers=headers)
|
||||
|
||||
|
||||
def _render_range(end_byte, with_bytes_prefix=True):
|
||||
return '{0}0-{1}'.format('bytes=' if with_bytes_prefix else '', end_byte - 1)
|
||||
def _render_range(num_uploaded_bytes, with_bytes_prefix=True):
|
||||
return '{0}0-{1}'.format('bytes=' if with_bytes_prefix else '', num_uploaded_bytes - 1)
|
||||
|
||||
|
||||
@v2_bp.route('/<namespace>/<repo_name>/blobs/uploads/', methods=['POST'])
|
||||
|
@ -133,7 +133,7 @@ def start_blob_upload(namespace, repo_name):
|
|||
return accepted
|
||||
else:
|
||||
# The user plans to send us the entire body right now
|
||||
uploaded = _upload_chunk(namespace, repo_name, new_upload_uuid, range_required=False)
|
||||
uploaded = _upload_chunk(namespace, repo_name, new_upload_uuid)
|
||||
uploaded.save()
|
||||
|
||||
return _finish_upload(namespace, repo_name, uploaded, digest)
|
||||
|
@ -184,7 +184,7 @@ def _parse_range_header(range_header_text, valid_start):
|
|||
return (start, length)
|
||||
|
||||
|
||||
def _upload_chunk(namespace, repo_name, upload_uuid, range_required):
|
||||
def _upload_chunk(namespace, repo_name, upload_uuid):
|
||||
""" Common code among the various uploading paths for appending data to blobs.
|
||||
Callers MUST call .save() or .delete_instance() on the returned database object.
|
||||
"""
|
||||
|
@ -195,9 +195,6 @@ def _upload_chunk(namespace, repo_name, upload_uuid, range_required):
|
|||
|
||||
start_offset, length = 0, -1
|
||||
range_header = request.headers.get('range', None)
|
||||
if range_required and range_header is None:
|
||||
_range_not_satisfiable(found.byte_count)
|
||||
|
||||
if range_header is not None:
|
||||
try:
|
||||
start_offset, length = _parse_range_header(range_header, found.byte_count)
|
||||
|
@ -240,7 +237,7 @@ def _finish_upload(namespace, repo_name, upload_obj, expected_digest):
|
|||
@require_repo_write
|
||||
@anon_protect
|
||||
def upload_chunk(namespace, repo_name, upload_uuid):
|
||||
upload = _upload_chunk(namespace, repo_name, upload_uuid, range_required=False)
|
||||
upload = _upload_chunk(namespace, repo_name, upload_uuid)
|
||||
upload.save()
|
||||
|
||||
accepted = make_response('', 204)
|
||||
|
@ -259,7 +256,7 @@ def monolithic_upload_or_last_chunk(namespace, repo_name, upload_uuid):
|
|||
if digest is None:
|
||||
raise BlobUploadInvalid()
|
||||
|
||||
found = _upload_chunk(namespace, repo_name, upload_uuid, range_required=False)
|
||||
found = _upload_chunk(namespace, repo_name, upload_uuid)
|
||||
return _finish_upload(namespace, repo_name, found, digest)
|
||||
|
||||
|
||||
|
|
Reference in a new issue