I have written some test to verify that a file exists on s3 and download when tried to test Storage::disk('s3')->temporaryUrl($url, $urlExpires);
It gives 500 error with this msg but the code works when test by the browser.
This driver does not support creating temporary URLs
Storage::fake('s3');
// Create attachment
$attachment = Attachment::create([
'name' => 'PDF Doc',
'url' => Storage::disk('s3')->put(
'attachments',
UploadedFile::fake()->create('document.pdf'),
1000)
]);
Storage::disk('s3')->assertExists($attachment->url);
...
$this->actingAs($user)
->get(route('attachments.download', $attachment->id))
->assertRedirect()
// it fails with with 500
$url = Attachment::find($id)->url;
if( Storage::disk('s3')->exists($url) ) {
// link expiration time
$urlExpires = Carbon::now()->addMinutes(10);
try {
$tempUrl = Storage::disk('s3')->temporaryUrl($url, $urlExpires);
return redirect($tempUrl);
} catch ( \Exception $e ) {
// Unable to test temporaryUrl, its giving driver dont support it issue.
return response($e->getMessage());
}
}
One more question?
Is there any way to customize the URL generated by temporaryUrl()
, problem is downloaded filename is some random string rlbPsVUhqubaXGoEQk96wjPXfQTqurJvNgVjRMZ8.doc
which is not very good, I like to customize the name of file to something like project-details.doc
etc 馃毝
This repo is for bug tracking. Use the forums or slack channel for solving your issue
Please ask on the forums, this repo is for bug reporting only. You can use https://laracasts.com/discuss or https://laravel.io/forum which are forums with a very large community of developers helping each other.
This is actually a bug, though. Minimal repro case:
public function test_foo()
{
Storage::fake('s3');
Storage::disk('s3')->temporaryUrl('some-url-here', Carbon::parse('tomorrow'));
}
You'll get this error:
[2018-04-09 13:44:49] testing.ERROR: RuntimeException: This driver does not support creating temporary URL
s.
Shouldn't the fake implementation respond to all of the same methods the real one does? At the very least, return the URL it was given, or no-op so that my test case doesn't fail just because I can't call this method on this adapter. This will muddy up the real test case which I need this behavior.
Can't we just return the $path if the filesystem adapter doesn't support temporary URLs, instead of throwing an exception?
I just experienced the same issue. We solved it by doing something like this:
Storage::shouldReceive('cloud')->twice()->andReturn(new class() {
public function temporaryUrl() {
return 'foo';
}
});
Hi @driesvints, could you take a second look at this?
Just returning a URL or a fake singed URL when faking a disk seems like a good solution.
We don't support this Laravel version anymore.
@driesvints This still exists in the current version of Laravel.
I think it's best that you send in a PR if something is broken here. There's a good workaround this right above here.
Most helpful comment
This is actually a bug, though. Minimal repro case:
You'll get this error:
[2018-04-09 13:44:49] testing.ERROR: RuntimeException: This driver does not support creating temporary URL s.
Shouldn't the fake implementation respond to all of the same methods the real one does? At the very least, return the URL it was given, or no-op so that my test case doesn't fail just because I can't call this method on this adapter. This will muddy up the real test case which I need this behavior.