Service not available when try to upload local files cloudinary + codeigniter - codeigniter

I have a problem when using cloudinary in codeigniter. At first, i integrate the library by following answers from
Upload image to Cloudinary using PHP Codeigniter
It worked when i uploaded online image. But failed when i tried to upload local image. The error is
Error in loading http://localhost/admin-simple/assets/img/avatar1_small.jpg - 503 Service Unavailable
Here is my code :
Cloudinary::config(array( "cloud_name" => "my_cloud_name", "api_key" => "1234", "api_secret" => "ABCD" ));
$data['upload'] = \Cloudinary\Uploader::upload("http://localhost/admin-simple/assets/img/avatar1_small.jpg");
$this->load->view('partials/sukses_upload_gambar',$data);
Can anyone help me ? Because i've been stuck for hours. Thanks.

According to Cloudinary documentation, when uploading a file from your computer, you should specify the filepath instead of the URL of your local server:
\Cloudinary\Uploader::upload("/home/my_image.jpg")
http://cloudinary.com/documentation/php_integration

Related

how use Image::make Laravel parse in ftp server using Storage

`
My Problem is the upload image laravel still error.
Internal server error, IDK where is wrong in my code
I'm using FTP cause it should be upload to external storage
Image intervention stream() facade used for upload image:
http://image.intervention.io/api/stream
$getFile = Image::make($request->file('image')->path())->resize(320, 240);
$image_thumb = $getFile->stream();
Storage::disk('ftp')->put($filenametostore, $image_thumb->__toString());

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 - Can't download file from storage at Ubuntu server with Nginx

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.

Laravel Intervention Image: Save image directly from dropbox url

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

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