@@ -967,24 +967,27 @@ def put(self, request, path, pk=None):
967967 """
968968 Create a blob from uploaded chunks.
969969
970- This request makes the upload complete. It can whether carry a zero-length
971- body or last chunk can be uploaded .
970+ This request makes the upload complete. It can either carry a zero-length
971+ body or contain the last chunk .
972972
973973 """
974974 _ , repository = self .get_dr_push (request , path )
975975
976976 digest = request .query_params ["digest" ]
977977 chunk = request .META ["wsgi.input" ]
978- # last chunk (and the only one) from monolitic upload
979- # or last chunk from chunked upload
980- last_chunk = ContentFile (chunk .read ())
981978 upload = get_object_or_404 (models .Upload , pk = pk , repository = repository )
982979
983- if artifact := upload .artifact :
980+ if upload .size == 0 :
981+ # monolithic upload to be completed in PUT
982+ artifact = self .create_single_chunk_artifact (chunk )
983+ elif artifact := upload .artifact :
984+ # chunked upload was completed in PATCH
984985 if artifact .sha256 != digest [len ("sha256:" ) :]:
985986 raise Exception ("The digest did not match" )
986987 artifact .touch ()
987988 else :
989+ # chunked upload to be completed in PUT
990+ last_chunk = ContentFile (chunk .read ())
988991 chunks = UploadChunk .objects .filter (upload = upload ).order_by ("offset" )
989992 with NamedTemporaryFile ("ab" ) as temp_file :
990993 for chunk in chunks :
0 commit comments