Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Libraries/Storage/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,15 @@ public function exists(string $filepath): bool
/**
* Upload a file to the resolved driver.
*
* @param UploadedFile $file file from http request
* @param string $dirpath full destination path including prefix
* @param UploadedFile $file file from http request
* @param string $dirpath full destination path including prefix
* @param string $filename optionally override file name
*
* @throws RuntimeException
*
* @return StorageResult
*/
public function upload(UploadedFile $file, string $dirpath): StorageResult
public function upload(UploadedFile $file, string $dirpath, string $filename = ''): StorageResult
{
try {
if ($this->pendingAutoDetect) {
Expand All @@ -188,7 +189,7 @@ public function upload(UploadedFile $file, string $dirpath): StorageResult
? $resolver->resolveExplicit($this->pendingDriver)
: $resolver->resolveDefault();

return $this->makeDriver($resolvedDriverName)->upload($file, $dirpath);
return $this->makeDriver($resolvedDriverName)->upload($file, $dirpath, $filename);
} finally {
$this->pendingDriver = null;
$this->pendingAutoDetect = false;
Expand Down
15 changes: 15 additions & 0 deletions tests/Libraries/Storage/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public function testUploadExplicitDriver(): void
$this->assertEquals(Storage::MINIO, $result->driver);
}

public function testUploadExplicitDriverWithFilenameOverride(): void
{
$diskMock = Mockery::mock();
LaravelStorage::shouldReceive('disk')->with('minio')->andReturn($diskMock);
$diskMock->shouldReceive('put')->once()->andReturn(true);

$fileMock = Mockery::mock(UploadedFile::class);
$fileMock->shouldReceive('getClientOriginalName')->andReturn('test.txt');
$fileMock->shouldReceive('getContent')->andReturn('content');

$storage = new Storage();
$result = $storage->driver(Storage::MINIO)->upload($fileMock, '/tmp', 'custom.txt');
$this->assertEquals(Storage::MINIO, $result->driver);
}

public function testUploadAutoDetectFails(): void
{
$storage = new Storage();
Expand Down
Loading