unable to retrieve images uploaded on aws instance using laravel - 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

Related

Laravel / Twilio: Twilio\Exceptions\ConfigurationException Credentials are required to create a Client

So I am trying to use the SMS (text message) function in Laravel / Twilio - I have a local machine which I tested it on and the credentials and everything works fine- I use the same code on my remote machine (which worked fine yesterday) and today I am getting an error: "Error: Credentials are required to create a Client"
I have triple confirmed the credentials are correct, I have even hard coded them into the code , I have moved them from the env file to config file and still not working - I have retested my local machine and it works still - I have copied the code from local machine (working) to remote machine and still not working - the only difference between the two is I have changed the SMTP settings in the env file (even if I remove this , the problem still exists). I have cleared cache, restarted services.
my .env file
TWILIO_SID=xxxxxxxxxx
TWILIO_TOKEN=xxxxxxxxxxxxxxx
TWILIO_FROM=+1xxxxxxxxxxxxx
my Twiliocontroller:
public function smsSend()
{
$receiverNumber = "+111111111";
$message = "Sup Dude";
try {
$account_sid = getenv("TWILIO_SID");
$auth_token = getenv("TWILIO_TOKEN");
$twilio_number = getenv("TWILIO_FROM");
$client = new Client($account_sid, $auth_token);
$client->messages->create($receiverNumber, [
"from" => $twilio_number,
"body" => $message,
"statusCallback" => "https://webhook.site/xxxxxxxxxxxxxx"
]);
dd('SMS Sent Successfully.');
} catch (Exception $e) {
dd("Error: " . $e->getMessage());
}
}
My web.php
Route::get('/smssend', [TwilioController::class, 'smsSend'])->name('smsSend');
Any help would be greatly appreciated

File Upload - Error executing ListObjects | AWS S3 & Laravel

I am getting the error below when i try to upload a file greater than 25mb to amazon s3 using laravel aws sdk, however files below 25mb are uploading successfully. I have everything setup correctly in my .env file. I have no idea why this is happening.
Any help would be appreciated.
Error:
Error executing "ListObjects" on
"bucketdomain/?prefix=b6d767d2f8ed5d21a44b0e5886680cb9%filename%2F&max-keys=1&encoding-type=url";
AWS HTTP error: cURL error 7: Failed to connect to bucketdomain
port 443: Network unreachable (see
http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Save function in laravel:
$v = Storage::disk('s3')->put($path, file_get_contents($file), 'public');
unlink($file->getPathname());
return response()->json(["message" => "File uploaded successfully!"]);
Upload function in laravel:
if ($receiver->isUploaded() === false) {
throw new UploadMissingFileException();
}
$save = $receiver->receive();
if ($save->isFinished()) {
database entries...
return $this->saveChunkFile($file,$userFolderName,$path,$fileName);
}
$handler = $save->handler();
return response()->json([
"Percentage" => $handler->getPercentageDone()
]);
I am using reusable.js in client side to upload files in chunks & the code above is to handle the chunks and merge them when done and pass to the saveChunkFile function.
Picture:
The file is to be stored in the 2nd folder from top but there is not file that is why i think the error is thrown on size function and these files (chunks) are being generated and not stopping still.

View [bcs.home.adminIndex] not found while uploading laravel 5.8 project on shared hosting

My laravel project is working fine on localhost but not working on live domain after I upload my project on shared hosting.
I have developed my laravel site on Windows machine and uploaded it on Linux machine. I have a /home route, after login users redirect to /home by checking user role. It works fine for one user named 'data entry' user but do not work for other users.
Here is my route -
Route::get('/home','HomeController#index')->name('index');
Here is my HomeController -
public function index()
{
if (auth::user()->userRole == 'super admin') {
return view('bcs.home.superAdminIndex');
}
if (auth::user()->userRole == 'admin') {
return view('bcs.home.adminIndex');
}
if (auth::user()->userRole == 'data entry') {
return view('bcs.home.dataEntryIndex');
}
if (auth::user()->userRole == 'payment verifier') {
return view('bcs.home.paymentVerifierIndex');
}
}

Intervention image on Heroku

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": "*",
...
}
}

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