Skip to content

Commit 3cddce2

Browse files
committed
Catch S3 getObject requests and return null
1 parent 63a3f98 commit 3cddce2

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/FileUploader/S3Uploader.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace EWZ\SymfonyAdminBundle\FileUploader;
44

5+
use Aws\S3\Exception\S3Exception;
56
use Aws\S3\S3Client;
67
use Ramsey\Uuid\Uuid;
78
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -161,10 +162,14 @@ public function getMimeType(string $fileName): ?string
161162
{
162163
$fileName = $this->cleanFileName($fileName);
163164

164-
$result = $this->s3Client->getObject([
165-
'Bucket' => $this->s3Bucket,
166-
'Key' => $fileName,
167-
]);
165+
try {
166+
$result = $this->s3Client->getObject([
167+
'Bucket' => $this->s3Bucket,
168+
'Key' => $fileName,
169+
]);
170+
} catch (S3Exception $e) {
171+
return null;
172+
}
168173

169174
if (isset($result['NoSuchKey'])) {
170175
return null;
@@ -180,10 +185,14 @@ public function getFileSize(string $fileName): ?int
180185
{
181186
$fileName = $this->cleanFileName($fileName);
182187

183-
$result = $this->s3Client->getObject([
184-
'Bucket' => $this->s3Bucket,
185-
'Key' => $fileName,
186-
]);
188+
try {
189+
$result = $this->s3Client->getObject([
190+
'Bucket' => $this->s3Bucket,
191+
'Key' => $fileName,
192+
]);
193+
} catch (S3Exception $e) {
194+
return null;
195+
}
187196

188197
if (isset($result['NoSuchKey'])) {
189198
return null;

0 commit comments

Comments
 (0)