I was trying to store image from dropbox url to my local folder with laravel Intervention , but with it i am getting errors after error.
Can anyone please tell me how can i do so ?
My code is this
$path = 'https://www.dropbox.com/s/vwswp91fiz0m1wd/1200px-Good_Food_Display_-_NCI_Visuals_Online.jpg?dl=0';
$filename = explode('?',basename($path))[0];
Image::make($path)->save('images/'.$filename);
The error i am getting for this is
Unable to init from given binary data.
So i tried the solution from of of stackoverflow post
$path = 'https://www.dropbox.com/s/vwswp91fiz0m1wd/1200px-Good_Food_Display_-_NCI_Visuals_Online.jpg?dl=0';
$filename = explode('?',basename($path))[0];
$path = base64_decode($path);
Image::make($path)->save('images/'.$filename);
But that gave me another error.
I tried looking on goggle but i didn't find any solid answer that works for my case
Can anyone please help me on this how to download image from dropbox url and save to loacal storage ? Or do i have to add dropbox api or something??
The dropbox link that you used https://www.dropbox.com/s/vwswp91fiz0m1wd/1200px-Good_Food_Display_-_NCI_Visuals_Online.jpg?dl=0 is a image preview page, which is not a valid image content. You can use force download mode to fetch the image content from dropbox, by editing the query parameter from ?dl=0 to ?raw=1.
$path = 'https://www.dropbox.com/s/vwswp91fiz0m1wd/1200px-Good_Food_Display_-_NCI_Visuals_Online.jpg?raw=1';
Image::make($path)->save('images/'.$filename);
See also: Force a file or folder to download, or to render on dropbox.com
Related
I have added Imagick library and tried to upload .heic image
$image = new \Imagick();
$image->readImage($request->image);
And always return this error
NoDecodeDelegateForThisImageFormat `HEIC' # error/constitute.c/ReadImage/509
I tried a lot of solutions but nothing works.
phpinfo
I solved the problem by adding this library then I make shell_exec(convert $path $newPath), Then Image::make($newPath)and finally upload the image after converted it from the serve.
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'.
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!
So I'm testing that a Laravel app that I just deployed to an Ubuntu server with Nginx works correctly, and I reached a point where I need to download some files that were upload from the front end using Angular.
I can upload files with no problem and I made sure that those are actually in the server and yeah, they are saved as expected.
However when I need to download them I get the error: "Failed to create the file"
It worked on my local machine, so I'm guessing is kind of a configuration problem but I'm not sure what to change yet.
The file is being requested through a GET request with Http with the header: { responseType: ResponseContentType.Blob }, the latter being part of Angular.
And in Laravel this is how I'm returning the file:
public function download($activityId) {
$activity = $activity = Activity::find($activityId, ['student_id', 'file_storage']);
$file = public_path() . '/storage/activityFiles/' . $activity['student_id'] . '/' . $activity['file_storage'];
return response()->download($file);
}
What can I be missing?
I decided to take a look at the laravel logs to see a little further the problem.
The problem was that I forgot to create the symbolic link to the storage.
That fixed the issue.
I am relatively new to Codeigniter, basically I choose CakePHP to develope applications. Now I am editing a Codeigniter Project, build in version 2. I have some images in my table and I need to disply it.
I have created a helper file general_helper.php in which I have a function
function image_url(){
return base_url().'uploads/';
}
So in view page , I tried to display image by
<img src="http://localhost/myapp/uploads/vendors/images/Desert.jpg" />
My directory structure is :
myapp
-uploads
-vendors
-images
-logos
But its not showing the image ! When I tried to put the image path in the url, it shows 404 error :( whats wrong ?
Codeigniter base_url function requires folder path relative to site's base url passed as parameters. Please try use below code.
First in constructor, please load your library -
$this->load->library('general');
Then please pass your uploads directory as parameter to base_url
function image_url(){
return base_url('uploads/');
}
If images are not uploading please do check image type.
Also try use log_message('info','info_message') function to record base url.
Please refer http://www.codeigniter.com/userguide2/general/errors.html