Reputation: 137
I have created the aws account and linked it on my laravel, the images are storing inside aws and also in my database.
but i do not want to use aws url but my own website url to access the image like so localhost:8000/images/uploads/image.jpg
private function storeImage($post)
{
if (request()->hasFile('image')){
$original = request()->file('image')->getClientOriginalName();
$post->update([
'image' => request()->file('image')->storeAs('uploads', $original),
]);
$image = Image::make(request()->file('image'));
Storage::disk('s3')->put('uploads', $image->stream(), 'public');
$image = Storage::disk('s3')->temporaryUrl("uploads", Carbon::now()->addMinutes(5));
$image = 'http://localhost:8000/images/';
}
}
I want this image link to change from the one below
@if($post->image)
<img class="post-image rectangle" src="{{ secure_asset('https://example-bucket.s3.eu-west-2.amazonaws.com/' . $post->image ) }}">
@endif
to something like this
@if($post->image)
<img class="post-image rectangle" src="{{ secure_asset('images/' . $post->image ) }}">
@endif
which displays an image link like this http://localhost:8000/images/uploads/image.jpg
mind you image is stored in my database like uploads/image.jpg
Upvotes: 1
Views: 934
Reputation: 823
You're storing it in a S3 bucket that's why it should be linked to the buckets domain. If you want to use your own domain, better off store it inside your site or better setup a custom domain for your S3 bucket.
Upvotes: 2