@@ -880,24 +880,27 @@ def put(self, request, path, pk=None):
880880 """
881881 Create a blob from uploaded chunks.
882882
883- This request makes the upload complete. It can whether carry a zero-length
884- body or last chunk can be uploaded .
883+ This request makes the upload complete. It can either carry a zero-length
884+ body or contain the last chunk .
885885
886886 """
887887 _ , repository = self .get_dr_push (request , path )
888888
889889 digest = request .query_params ["digest" ]
890890 chunk = request .META ["wsgi.input" ]
891- # last chunk (and the only one) from monolitic upload
892- # or last chunk from chunked upload
893- last_chunk = ContentFile (chunk .read ())
894891 upload = get_object_or_404 (models .Upload , pk = pk , repository = repository )
895892
896- if artifact := upload .artifact :
893+ if upload .size == 0 :
894+ # monolithic upload to be completed in PUT
895+ artifact = self .create_single_chunk_artifact (chunk )
896+ elif artifact := upload .artifact :
897+ # chunked upload was completed in PATCH
897898 if artifact .sha256 != digest [len ("sha256:" ) :]:
898899 raise Exception ("The digest did not match" )
899900 artifact .touch ()
900901 else :
902+ # chunked upload to be completed in PUT
903+ last_chunk = ContentFile (chunk .read ())
901904 chunks = UploadChunk .objects .filter (upload = upload ).order_by ("offset" )
902905 with NamedTemporaryFile ("ab" ) as temp_file :
903906 for chunk in chunks :
0 commit comments