The uploadFile method of Space class updated

This commit is contained in:
Juh Champ 2022-03-05 01:52:04 -03:00
parent d7f0b36dc1
commit b7d1a40e70
2 changed files with 6 additions and 2 deletions

View file

@ -302,16 +302,20 @@ class Space
* Upload a file * Upload a file
* *
* @param string $filepath The path to the file, including the filename. Relative and absolute paths are accepted. * @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 $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 * @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([ $this->s3->putObject([
'Bucket' => $this->name, 'Bucket' => $this->name,
'Key' => ($filename) ?: basename($filepath), 'Key' => ($filename) ?: basename($filepath),
'SourceFile' => $filepath, 'SourceFile' => $filepath,
'ContentType' => $mimeType,
'ACL' => ($private) ? 'private' : 'public-read'
]); ]);
return new File($this, ($filename) ?: basename($filepath), [], false); return new File($this, ($filename) ?: basename($filepath), [], false);

View file

@ -82,7 +82,7 @@ class SpaceTest extends TestCase
public function testCanUploadFile() public function testCanUploadFile()
{ {
$tmpFile = tempnam(sys_get_temp_dir(), 'spaces-test'); $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); $this->assertInstanceOf(File::class, $file);
} }