Can't access VaporImage #3186
-
Description:I have a VaporImage::make('Featured Image')
->help('Upload a featured image for the post that will display on landing pages ')
->storeAs(function ($request) {
$img = $request->input('vaporFile')['featured_image'];
return $img['key'].'.'.$img['extension'];
}), The upload works, Nova displays the preview, and all is well. However, the On the front end, if I do There are 2 things here I guess
I can't call if this is a Nova thing or a Vapor thing or if it's even a bug, undocumented or documented and I've totally missed it. |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 4 replies
-
I personally never seen an example using You might also want to ask if anyone has tried something similar on #nova on Laravel's Discord or other support channel listed at https://nova.laravel.com/docs/3.0/support.html#support-questions |
Beta Was this translation helpful? Give feedback.
-
Thank you. Yeah, I've trawled through all the usual places; Discord, SO,
Vapor's Github issues as well as Nova's and there was a reference in #2970
to the storeAs method but nothing for the issue I'm running into.
…On Tue, 19 Jan 2021 at 13:22, Mior Muhammad Zaki ***@***.***> wrote:
I personally never seen an example using VaporImage with storeAs(), but
will check it out tommorow.
You might also want to ask if anyone has tried something similar on #nova
on Laravel's Discord <https://discordapp.com/invite/mPZNm7A> or other
support channel listed at
https://nova.laravel.com/docs/3.0/support.html#support-questions
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3180 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA3OWKKBZ6SFNE3W2LTVKLS2WBSXANCNFSM4WIVL3RQ>
.
--
Steven Grant
|
Beta Was this translation helpful? Give feedback.
-
Based on the code review, since you explicitly call E.g: VaporImage::make('Featured Image')
->help('Upload a featured image for the post that will display on landing pages ')
->storeAs(function ($request) {
$img = $request->input('vaporFile')['featured_image'];
return str_replace('tmp/', '', $img['key']).'.'.$img['extension'];
}), |
Beta Was this translation helpful? Give feedback.
-
Right, that won't solve the issue of displaying the image |
Beta Was this translation helpful? Give feedback.
-
You mean using Wouldn't you need to access the the URL via Storage? https://laravel.com/docs/8.x/filesystem#file-urls |
Beta Was this translation helpful? Give feedback.
-
yeah, it doesn't resolve. I wouldn't have thought so because the `{{ asset() }}` helper is supposed to route to the s3 bucket?
…On Wed, 20 Jan 2021 at 09:42, Mior Muhammad Zaki ***@***.***> wrote:
You mean using {{ asset($post->featured_image) }}?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3180 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA3OWLSV47CXUIPJZLHJV3S22QRPANCNFSM4WIVL3RQ>
.
--
Steven Grant
|
Beta Was this translation helpful? Give feedback.
-
Use |
Beta Was this translation helpful? Give feedback.
-
thanks for that added my own helper function function s3Url($file): string
{
$disk = Storage::disk('s3');
$disk->setVisibility($file, 'public');
return $disk->url($file);
} |
Beta Was this translation helpful? Give feedback.
-
Here's another approach to solve this problem: <?php
namespace App\Support;
use Illuminate\Support\Facades\Storage;
use Laravel\Nova\Fields\VaporImage;
class PublicVaporImage extends VaporImage
{
protected function storeFile($request, $requestAttribute)
{
$filePath = parent::storeFile($request, $requestAttribute);
$disk = Storage::disk($this->getStorageDisk());
$disk->setVisibility(rtrim($filePath, '/'), 'public');
return $filePath;
}
} Simply use |
Beta Was this translation helpful? Give feedback.
Use
Storage::url()
,asset()
are only meant for file stored on the application instance. Vapor store everything on s3.