How to get full URL of image after Amazon S3 upload? - laravel

I need to get full URL of an image which is uploaded to amazon s3. I tried following functions. I am using Laravel 5.1.
Storage::disk("s3")->url($filename);
Storage::url($filename);
Storage::temporaryUrl('file1.jpg', Carbon::now()->addMinutes(5));
$filesystem->getAdapter()->getClient()->getObjectUrl($bucket, $key);
all are showing undefined function url(or) temporaryUrl (or) getObjectUrl.

The url() and temporaryUrl() methods aren't available in Laravel 5.1 (FileSystemAdapter - API Reference 5.1). They became available as of version 5.4 (FileSystemAdapter - API Reference 5.4).

Related

How to retrieve files from S3 in Laravel Vapor

I'm having a problem loading images in my html dynamically after storing them successfully with Laravel Vapor.
I have followed this documentation provided by laravel vapor to store files, and it works like a charm. I copy my uploaded files from the tmp directory into the root of my S3 bucket and then store the path of that file in my databases images table so that later I can return the file path to my front end and display the image in my browser.
Unfortunately this is always returning a 403 status code from AWS S3.
I could fix this by making my generated S3 bucket public, but that would raise a security issue. I believe this should work out of the box, not sure where I could have gone wrong... any ideas?
I am returning the uploaded image url using the Storage facade.
use Illuminate\Support\Facades\Storage;
return Storage::url($image->path);
Where $image->path is the file path in my S3 bucket.
I'm sure that the storage facade is working correctly because it is returning the correct url with the file's path.
I got the solution to this problem. I contacted laravel vapor support and I was told to set the visibility property for my file to public when I copy it to the permanent location, as stated in Laravel's official documentation here.
So after you upload your file using the js vapor.store method you should copy it to a permanent directory, then set it's visibility to public.
Storage::copy($request->path, str_replace('tmp/', '', $request->path));
Storage::setVisibility(str_replace('tmp/', '', $request->path), 'public');
I also noticed that your can set the visibility of the file directly in the vapor.store method by passing a visibility attribute with the respective value.
vapor.store(file, { visibility: 'public-read' });
As a side note: just 'public' will return a 400 bad request, it must be set to 'public-read'.

laravel XMLHttpRequest cannot load https://website.com/images/1554690945.png. No 'Access-Control-Allow-Origin' header is present

I'm having problem with my laravel file system CORS, I'm trying to cache the image from the url (which is also my website) in my ionic application but it's failing because of the error. I tried the image from https://reqres.in/api/users/1 and there is no problem caching the image in my ionic application. I guess the problem here is in my laravel website
In one of my current projects I have to save 200+ images in my Ionic App from a request to my server.
The way I handled this problem was converting the image to Base64 using Image Intervention and responding to the request with back to the app to then save the Base64 in the Ionic Storage like so.
Laravel Controller
public function grabImages(Request $request){
$image = (string) Image::make('public/bar.png')->encode('data-url');
$data = {
'base64' : $image,
'file_name' : 'test'
}
return $data;
}
Ionic
After receiving the data you can just store it in the Ionic Storage and access it wherever you would like to, even offline.
To display it all you have to do is set the image source to the Base64.
Using this method also solves a few problems, such as the user cannot see the images in the image gallery, as well as allows you to store them and use them offline for as long as you would like and remove them whenever.
As ImJT said I am using the barryvdh's laravel-cors plugin as well.
Hope this answered your question, good luck!

laravel is saving the wrong image link in db

I am trying to save the image link in the db like this
'photo' => asset('uploads/'.$fileName2)));
and in the db it is being saved as
http://localhost:8000/uploads/8730.jpeg
irrespective of the url in config file
APP_URL=http://example.com
asset() helper function generates
a URL for an asset using the current scheme of the request
https://laravel.com/docs/5.3/helpers#method-asset
Then, When you access to your laravel app via http://localhost:8000/, asset('uploads/'.$fileName2) will returns http://localhost:8000/uploads/....

how can we use firebase image file and resize them using get_Serving_URL

I just started using google cloud services
and found that the following can be only implemented using blob but i want to use image name from cloud storage.
Is there a way to resize the images using servingURL if so
how can i implement it i.e. how can i give the bucket name and image name from cloud storage ?
and construct the URL and pass the parameters
is there any blog or code that i can refer ?
The get_serving_url() is part of App Engine and thus you can't use it in Firebase (unless Firebase will eventually supports it), but you can definitely store the images in the Google Cloud Storage instead of Blobstore, which is by the way is the recommended way.
here is the blog to resize the image
This is the sample PHP code but how to make it working in FireBase you need to refer the link below
click here to read more
index.php:
<?php
//var_dump($_FILES['uploaded_files']['tmp_name']);
syslog(LOG_WARNING, "Request came");
require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;
syslog(LOG_WARNING, "Imported Cloud Storage Tools");
//var_dump( $_GET);
$object_url=$_GET["image"];
$size=intval($_GET["size"]);
syslog(LOG_WARNING, "Object URL $object_url");
syslog(LOG_WARNING, "Size $size");
$bucket="gs://YOUR-PROJECT-ID.appspot.com/bucket_name/";
$object_image_url = CloudStorageTools::getImageServingUrl($object_url,['size' => $size, 'crop' => false]);
syslog(LOG_WARNING, "Output Url $object_image_url");
header("location: $object_image_url");
closelog();
?>
app.yaml:
runtime: php55
api_version: 1
handlers:
- url: /.*
script: index.php
You can use Firebase Javascript SDK to send your files to Google Storage, and build an API samples with PHP + library from AppEngine for generating the URL of the object, are same bucket locate.
In app PHP, remember to put following content in app.yaml:
runtime: php55
api_version: 1
handlers:
- url: /.*
script: index.php
Before, using gcloud, deploy your sample API:
gcloud app deploy

blueimp jQuery-File-Upload not working for laravel 5

i am using , https://github.com/blueimp/jQuery-File-Upload plugin for image upload using ajax call in laravel 5. i also refered article http://peterjolson.com/using-laravel-and-jquery-file-upload/. but i am getting the following error error
GET http://localhost:8000/...../server/php/ 500 (Internal
Server Error)
when i use https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin i get the same error. Can anyone help with this or please suggest any working image uploader with ajax call for laravel 5
There is a main.js file, you need to adjust the url there according to the path you store it:
url: '../../uploadimage/server/php/'

Resources