From b7d1a40e70921660b1479c77396f78a6a76ca7d8 Mon Sep 17 00:00:00 2001 From: Juh Champ <44661803+juhchamp@users.noreply.github.com> Date: Sat, 5 Mar 2022 01:52:04 -0300 Subject: [PATCH 1/2] The uploadFile method of Space class updated --- SpacesAPI/Space.php | 6 +++++- tests/SpaceTest.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SpacesAPI/Space.php b/SpacesAPI/Space.php index cffcbde..74a7230 100644 --- a/SpacesAPI/Space.php +++ b/SpacesAPI/Space.php @@ -302,16 +302,20 @@ class Space * Upload a file * * @param string $filepath The path to the file, including the filename. Relative and absolute paths are accepted. + * @param string $mimeType The file mime type to pass as ContentType for the file (e.g. 'image/jpeg'). * @param string|null $filename The remote filename. If `null`, the local filename will be used. + * @param bool $private True for the file to be private, false to allow public access. * * @return \SpacesAPI\File */ - public function uploadFile(string $filepath, ?string $filename = null): File + public function uploadFile(string $filepath, string $mimeType, ?string $filename = null, bool $private = true): File { $this->s3->putObject([ 'Bucket' => $this->name, 'Key' => ($filename) ?: basename($filepath), 'SourceFile' => $filepath, + 'ContentType' => $mimeType, + 'ACL' => ($private) ? 'private' : 'public-read' ]); return new File($this, ($filename) ?: basename($filepath), [], false); diff --git a/tests/SpaceTest.php b/tests/SpaceTest.php index f416539..0ccccef 100644 --- a/tests/SpaceTest.php +++ b/tests/SpaceTest.php @@ -82,7 +82,7 @@ class SpaceTest extends TestCase public function testCanUploadFile() { $tmpFile = tempnam(sys_get_temp_dir(), 'spaces-test'); - $file = self::$space->uploadFile($tmpFile, 'upload-test.txt'); + $file = self::$space->uploadFile($tmpFile, 'text/plain', 'upload-test.txt', false); $this->assertInstanceOf(File::class, $file); } From dc5dc27ff330f6ed01a52da3cb8bb5ad24730626 Mon Sep 17 00:00:00 2001 From: Juh Champ <44661803+juhchamp@users.noreply.github.com> Date: Wed, 23 Mar 2022 16:58:37 -0300 Subject: [PATCH 2/2] uploadFile method of Space class updated and testCanUploadFileWithMimeType method added to SpaceTest. --- SpacesAPI/Space.php | 4 ++-- tests/SpaceTest.php | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/SpacesAPI/Space.php b/SpacesAPI/Space.php index 74a7230..a257062 100644 --- a/SpacesAPI/Space.php +++ b/SpacesAPI/Space.php @@ -302,13 +302,13 @@ class Space * Upload a file * * @param string $filepath The path to the file, including the filename. Relative and absolute paths are accepted. - * @param string $mimeType The file mime type to pass as ContentType for the file (e.g. 'image/jpeg'). * @param string|null $filename The remote filename. If `null`, the local filename will be used. + * @param string|null $mimeType The file mime type to pass as ContentType for the file (e.g. 'image/jpeg'). * @param bool $private True for the file to be private, false to allow public access. * * @return \SpacesAPI\File */ - public function uploadFile(string $filepath, string $mimeType, ?string $filename = null, bool $private = true): File + public function uploadFile(string $filepath, ?string $filename = null, ?string $mimeType = null, bool $private = true): File { $this->s3->putObject([ 'Bucket' => $this->name, diff --git a/tests/SpaceTest.php b/tests/SpaceTest.php index 0ccccef..976d9f6 100644 --- a/tests/SpaceTest.php +++ b/tests/SpaceTest.php @@ -82,7 +82,14 @@ class SpaceTest extends TestCase public function testCanUploadFile() { $tmpFile = tempnam(sys_get_temp_dir(), 'spaces-test'); - $file = self::$space->uploadFile($tmpFile, 'text/plain', 'upload-test.txt', false); + $file = self::$space->uploadFile($tmpFile, 'upload-test.txt'); + $this->assertInstanceOf(File::class, $file); + } + + public function testCanUploadFileWithMimeType() + { + $tmpFile = tempnam(sys_get_temp_dir(), 'spaces-test'); + $file = self::$space->uploadFile($tmpFile, 'upload-test.txt', 'text/plain'); $this->assertInstanceOf(File::class, $file); }