Intervention image on Heroku - laravel

I am working on an app in Laravel which uses Intervention Image library and Imagick to upload and resize images on the fly. Following is my code:
public function saveImage($directory, $imageObject) {
$imageFile = $imageObject->store('app/'.$directory);
$filename = str_replace('app/'.$directory.'/','',$imageFile);
$imageObject = Storage::get($imageFile);
$img = Image::make($imageObject);
$img->resize(null, 40, function ($constraint) {
$constraint->aspectRatio();
});
$imageFile = $img->stream();
Storage::put('app/'.$directory.'/'.$filename, $imageFile->__toString());
// $img->save($imagePath);
return $filename;
}
However the problem occurs on the line Image::make($imageObject). The only error which Heroku returns is 503 Service Unavailable. Please help.

Imagick is a library that needs to be installed on the machine. From heroku docs:
The following built-in extensions have been built “shared” and can be
enabled through composer.json (internal identifier names given in
parentheses):
Add the code from this answer to your composer.json-https://stackoverflow.com/a/35660753/2460352:
...
"require": {
"ext-imagick": "*",
...
}
}

Related

Hybridauth on Codeigniter Could not load the Hybrid_Auth class

I have installed hybridauth via composer and then followed the steps given here, but always get the following error:
Could not load the Hybrid_Auth class
Any solution to this?
Use:
$this->load->library('hybridauth');
in your controller to load the library.
application/composer.json
{
"require" : {
"hybridauth/hybridauth" : "~3.0"
},
"config": {
"platform": {
"php": "X.X.XX" //SET your php version
}
}
}
and change config file application/config/config.php
$config['composer_autoload'] = TRUE;

unable to retrieve images uploaded on aws instance using laravel

i am trying to upload image via laravel and then retrieve its url to save in database and return back to the front end application , image upload is working fine at localhost but not at ec2 instance .
Image is uploaded successfully and can be downloaded via filezilla also
i have setup chmod -R 777 for the storage directory in laravel but its still not working
public static function upload_files($type, $file, $id)
{
if ($type == 'profile_pic') {
$image = $file->store('profile_pic','public');
$image = asset('storage/'.$image);
if ($image) {
return $image;
} else {
return false;
}
}
}
it return http://localhost/trip/public/storage/profile_pic/MaHskQD2VcLSlC11VV3agbBNdh7j7k82liewYBw3.png at localhost and when i click on the link, image is loaded successfully
while on my server it loads
http://mydomain/storage/app/profile_pic/MaHskQD2VcLSlC11VV3agbBNdh7j7k82liewYBw3.png and throws 404 not found error
result of ls -lrt is "-rwxrwxrwx 1 apache ec2-user 190916 Jan 23 10:06 MaHskQD2VcLSlC11VV3agbBNdh7j7k82liewYBw3.png"
please run this command on your mydomain terminal:
php artisan storage:link

Laravel 5.3 response()->download - File(.doc, .docx) becomes unreadable after downloading

Laravel 5.3
When I download a file (.doc, .docx) from my storage folder it becomes unreadable. If I go to the local folder and open the file however it is valid and readable.
I am using the standard download function, using headers and stuff.. Have a look at my code:
$fileNameGenerate = 'example_filename';
$fileArr = [ 'wierd_filename', 'docx' ];
$cvPath = storage_path('app/example_folder/subfolder/wierd_filename.docx');
$headers = array(
'Content-Type: application/' . $fileArr[1],
);
try {
return response()->download($cvPath, $fileNameGenerate . '.' . $fileArr[1], $headers);
} catch (\Exception $e) {
//Error
return redirect()->back()->with('error', trans('locale.file_does_not_exists'));
}
Does anyone know what is wrong here? Thank you!
Update: I removed headers, it doesn't work with or without them.
Here is how the files render in the 2 different cases:
Try this
public function getDownload()
{
//doc file is stored under storagepath/download/info.docx
$file= pathofstorage. "/download/info.docx";
return response()->download($file);
}
I added:
ob_end_clean();
before:
response -> download
and it worked for me.

Installing Package in Laravel VIA Composer

i am currently using laravel 4 for my project, i download a package that turns youtube/vimeo urls into embed, i required the package in my composer and run composer update.
However now i am trying to use this package but i keep getting an error:
Class 'Embed' not found
The code for this is in my helpers.php file:
function embed_video($url, $width = 0, $height = 0)
{
$embed = Embed::make($url)->parseUrl();
if ($embed) {
// Set width of the embed.
if ($width > 0)
{
$embed->setAttribute(['width' => $width]);
}
// Set height of the embed.
if ($height > 0)
{
$embed->setAttribute(['height' => $height]);
}
return $embed->getHtml();
}
}
I call this function in my view.
This is the link for the package: cohensive

Moved Laravel dir to root of server now composer update fails

I wanted the Laravel 4.1 package to be at the root of a particular web server so I took it out of it's "laravel" dir and moved it.
Used to be in: C:\www\mysite.dev\laravel
Now it is in: C:\www\mysite.dev
When I run composer update it chokes producing the error:
{"error":{"type":"ErrorException","message":"mkdir(): No such file or directory","file":"C:\\www\\mysite.dev\\vendor\\laravel\\framework\\src\\Illuminate\\Filesystem\\Filesystem.php","line":302}}
How can I configure composer.json to compensate for this change?
It seems like problem with permissions.
Line 302 of Filesystem.php is the following (in bold):
public function makeDirectory($path, $mode = 0777, $recursive = false, $force = false)
{
if ($force)
{
return #mkdir($path, $mode, $recursive);
}
else
{
302 return mkdir($path, $mode, $recursive);
}
}

Resources