@@ -78,10 +78,9 @@ public function patchUpload(string $id, Request $request): Response
7878 throw $ this ->client404NotFoundExceptionFactory ->createFromTemplate ();
7979 }
8080
81- if ($ uploadElement ->getUploadOwner () !== $ userId ) {
81+ if ($ uploadElement ->getUploadOwner ()?->toString() !== $ userId-> toString () ) {
8282 throw $ this ->client404NotFoundExceptionFactory ->createFromTemplate ();
8383 }
84-
8584 if ($ uploadElement ->getExpires () < new DateTime ()) {
8685 throw $ this ->client410GoneExceptionFactory ->createFromTemplate ();
8786 }
@@ -99,7 +98,7 @@ public function patchUpload(string $id, Request $request): Response
9998
10099 $ patchResource = $ request ->getContent (true );
101100
102- $ currentChunkIndex = $ uploadElement ->getAlreadyUploadedChunks ();
101+ $ currentChunkIndex = $ uploadElement ->getAlreadyUploadedChunks () + 1 ;
103102 $ nextChunkKey = $ this ->fileService ->getUploadBucketKey ($ uploadId , $ currentChunkIndex );
104103
105104 $ this ->s3Client ->putObject ([
@@ -119,6 +118,8 @@ public function patchUpload(string $id, Request $request): Response
119118 throw $ this ->server500LogicExceptionFactory ->createFromTemplate ('Unable to read content length of created chunk. ' );
120119 }
121120
121+ // update uploadelement to update chunk index +1 and upload offset + n bytes
122+
122123 $ canCreateFile = false ;
123124
124125 if (null !== $ partialUploadRequest ->getContentLength ()
@@ -133,8 +134,15 @@ public function patchUpload(string $id, Request $request): Response
133134 $ uploadElement ->setUploadComplete (true );
134135 }
135136
136- $ uploadElement ->setUploadOffset ($ uploadElement ->getUploadOffset () + $ contentLength );
137- $ uploadElement ->setAlreadyUploadedChunks ($ uploadElement ->getAlreadyUploadedChunks () + 1 );
137+
138+ // print_r($uploadElement);
139+
140+ $ uploadElement = $ uploadElement
141+ ->setUploadOffset ($ uploadElement ->getUploadOffset () + $ contentLength )
142+ ->setAlreadyUploadedChunks ($ uploadElement ->getAlreadyUploadedChunks () + 1 );
143+
144+ // print_r($uploadElement);
145+ // exit;
138146
139147 $ this ->elementManager ->merge ($ uploadElement );
140148 $ this ->elementManager ->flush ();
@@ -168,14 +176,15 @@ public function createFile(UploadElement $uploadElement, UuidInterface $uploadTa
168176 $ parts = [];
169177
170178 try {
171- for ($ i = 0 ; $ i <= $ uploadElement ->getAlreadyUploadedChunks (); ++$ i ) {
179+ for ($ i = 1 ; $ i <= $ uploadElement ->getAlreadyUploadedChunks (); ++$ i ) {
172180 $ sourceKey = $ this ->fileService ->getUploadBucketKey ($ uploadId , $ i );
173181 // todo: possible bug with upload bucket vs storage bucket; needs to be tested live
174182 $ copyResult = $ this ->s3Client ->uploadPartCopy ([
175- 'Bucket ' => $ this ->emberNexusConfiguration ->getFileS3UploadBucket (),
183+ 'Bucket ' => $ this ->emberNexusConfiguration ->getFileS3StorageBucket (),
176184 'Key ' => $ targetKey ,
177185 'UploadId ' => $ multipartUploadId ,
178- 'PartNumber ' => $ i + 1 ,
186+ // 'PartNumber' => $i + 1,
187+ 'PartNumber ' => $ i ,
179188 'CopySource ' => sprintf ('%s/%s ' , $ this ->emberNexusConfiguration ->getFileS3UploadBucket (), $ sourceKey ),
180189 ]);
181190
@@ -185,7 +194,8 @@ public function createFile(UploadElement $uploadElement, UuidInterface $uploadTa
185194 }
186195
187196 $ parts [] = [
188- 'PartNumber ' => $ i + 1 ,
197+ // 'PartNumber' => $i + 1,
198+ 'PartNumber ' => $ i ,
189199 'ETag ' => $ copyPartResult ->getETag (),
190200 ];
191201 }
@@ -199,6 +209,7 @@ public function createFile(UploadElement $uploadElement, UuidInterface $uploadTa
199209 ],
200210 ]);
201211
212+ // important todos:
202213 // todo: delete original file, if it a) existed and b) had a different file extension
203214 // todo: set file property to actual element, merge and flush it?
204215 } catch (Throwable $ e ) {
0 commit comments