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
39 changes: 37 additions & 2 deletions src/AzureStorageBlobAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,48 @@ public function url($path)
return $this->adapter->publicUrl($path, new Config);
}

/** @phpstan-ignore-next-line */
/**
* Get a temporary URL for the file at the given path.
*
* @param string $path
* @param \DateTimeInterface $expiration
* @return string
*/
/** @phpstan-ignore-next-line */
public function temporaryUrl($path, $expiration, array $options = [])
{
return $this->adapter->temporaryUrl(
$path,
$expiration,
new Config(['permissions' => 'r'])
new Config(array_merge(['permissions' => 'r'], $options))
);
}

/**
* Get a temporary upload URL for the file at the given path.
*
* @param string $path
* @param \DateTimeInterface $expiration
* @return array{url: string, headers: array<string, string>}
*/
/** @phpstan-ignore-next-line */
public function temporaryUploadUrl($path, $expiration, array $options = [])
{
$url = $this->adapter->temporaryUrl(
$path,
$expiration,
new Config(array_merge(['permissions' => 'cw'], $options))
);
$contentType = isset($options['content-type']) && is_string($options['content-type'])
? $options['content-type']
: 'application/octet-stream';

return [
'url' => $url,
'headers' => [
'x-ms-blob-type' => 'BlockBlob',
'Content-Type' => $contentType,
],
];
}
}
22 changes: 21 additions & 1 deletion tests/AzureStorageBlobAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,27 @@ public function driver_works(): void
self::assertFalse($driver->exists('file2.txt'));
self::assertTrue($driver->exists('file3.txt'));

self::assertCount(2, $driver->allFiles());
// Test temporary upload URL functionality
// Generate a temporary upload URL
$uploadData = $driver->temporaryUploadUrl('temp-upload-test.txt', now()->addMinutes(5), [
'content-type' => 'text/plain',
]);

// Upload content directly to the URL
$content = 'This content was uploaded directly to a temporary URL';
$response = Http::withHeaders($uploadData['headers'])
->withBody($content, 'text/plain')
->put($uploadData['url']);

// Verify the upload was successful
self::assertTrue($response->successful());

// Verify the file exists and has the correct content
self::assertTrue($driver->exists('temp-upload-test.txt'));
self::assertEquals($content, $driver->get('temp-upload-test.txt'));

// Count files and clean up
self::assertCount(3, $driver->allFiles()); // file.txt, file3.txt, and temp-upload-test.txt

$driver->deleteDirectory('');

Expand Down