I'm trying to upload files to Amazon s3 using Laravel 5.8, it actually works on locally but I am unable to get it to work online. I got error:
Class 'League\Flysystem\AwsS3v3\AwsS3Adapter' not found
I've run 'composer dump-autoload', 'composer install'commands I've even tried to upload vendor folder. The .env file is the same locally and online so I'm pretty sure that is not a credentials problem.
This is my post code:
public function postUpload(StoreImage $request)
{
$path = Storage::disk('s3')->put('images/registry', $request->file, 'public');
$request->merge([
'size' => $request->file->getClientSize(),
'path' => $path,
'auth_by' => $request->patient
]);
$this->image->create($request->only('path', 'title', 'size', 'auth_by'));
return back()->with('success', 'Image Successfully Saved');
}
So I'm getting this error:
Please any help would be great :).
You should install AWS adapter package
composer require league/flysystem-aws-s3-v3
Related
ERROR:
Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension
I put this code on my cache.php
'default' => env('CACHE_DRIVER', 'redis'),
And those code in my controller:
$data['posts'] = cache('posts',function(){
Post::with('user')
->select('title', 'created_at', 'user_id', 'thumbnail_path', 'content')
->orderBy('created_at','desc')
->take(50)
->get();
});
Firstly, you need to make sure you have actually installed predis using composer by running this in your terminal:
composer require predis/predis
And then you need to make sure that your have this set in your .env file
REDIS_CLIENT=predis
This is covered in the docs:
https://laravel.com/docs/6.x/redis
I got this error message when I hosted my Laravel app on cloudways.com. I fixed it by installing Redis and Supervisord from the server 'Settings & Packages' page.
I have a problem. I'm using Bootstrap fileinput to upload 52 images with async AJAX requests. It uploads 90% of the files and randomly gives errors on few of the images.
This is the error:
SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO)
Upload function:
public function uploadTemp360(Request $request)
{
$image = $request->file('view360s');
$fileName = $image->getClientOriginalName().'.'.$image->getClientOriginalExtension();
$path = public_path().'/uploads/temp/';
if ($image->isValid()){
$image->move($path, $fileName);
}
return [
'initialPreview' => [
"<img style='height:160px' src='/uploads/temp/".$fileName."' class='file-preview-image'>",
],
'initialPreviewConfig' => [
['caption' => $fileName, 'width' => '120px', 'url' => route('admin.products.delete-temp-360'), 'key' => $fileName, 'size' => \File::size($path.$fileName)],
],
'append' => true,
'filename' => $fileName,
];
}
I don't know what's going on and how is it causing DB error by running this code...
I have found in laravel log this error:
production.ERROR: exception 'RuntimeException' with message 'The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.'
This could be a problem with the Laravel app key. Try executing these two commands in the following order using the command line from your projects root directory:
php artisan key:generate
php artisan config:clear
You can also try making sure that in your config/app.php file you have the following and try to clear the config again:
'cipher' => 'AES-128-CBC',
It seems your database connection is being closed. Using following code you can keep you connection alive after each image upload.
DB::reconnect();
I have fixed that issue with running command: php artisan config:cache. It was problem because of Laravel can't read .env file sometimes...
How do I integrate my Yii 2.0 project with Aws ?
I have installed it using composer
"aws/aws-sdk-php": "2.*",
and included the
require '../vendor/aws/aws-autoloader.php';
But when I try to instantiate my S3 client, it keeps telling me that Aws does not exist.
You can refer the following link on github
https://github.com/JDpawar/yii2-aws-s3-sdk
It has the exact details how to use the S3 SDK along with the Yii 2 App.
AWS SDK for Yii2 - Use Amazon Web Services in your Yii2 project
This extension provides the AWS SDK 3 integration for the Yii2 framework
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist fedemotta/yii2-aws-sdk "*"
or add
"fedemotta/yii2-aws-sdk": "*"
to the require section of your composer.json file.
Note: You can still use AWS version 2 if you specify fedemotta/yii2-aws-sdk "1.*"
Usage
To use this extension, simply add the following code in your application configuration:
<?php
return [
//....
'components' => [
'awssdk' => [
'class' => 'fedemotta\awssdk\AwsSdk',
'credentials' => [ //you can use a different method to grant access
'key' => 'your-aws-key',
'secret' => 'your-aws-secret',
],
'region' => 'your-aws-region', //i.e.: 'us-east-1'
'version' => 'your-aws-version', //i.e.: 'latest'
],
],
];
?>
Getting all balancer names from AWS:
<?php
$aws = Yii::$app->awssdk->getAwsSdk();
$elb = $aws->createElasticloadbalancing();
$load_balancers = $elb->describeLoadBalancers()->toArray();
if (isset($load_balancers['LoadBalancerDescriptions'])){
foreach ($load_balancers['LoadBalancerDescriptions'] as $balancer){
if (isset($balancer['LoadBalancerName'])){
echo $balancer['LoadBalancerName'];
}
}
}
?>
Download an object from S3:
<?php
//specify the region if it is different than the main configuration region
Yii::$app->awssdk->region = 'sa-east-1';
$aws = Yii::$app->awssdk->getAwsSdk();
//use s3
$s3 = $aws->createS3();
$result = $s3->listObjects(['Bucket' => 'your-bucket-id',
"Prefix" => "your-path"])->toArray();
//get the last object from s3
$object = end($result['Contents']);
$key = $object['Key'];
$file = $s3->getObject([
'Bucket' => 'your-bucket-id',
'Key' => $key
]);
//download the file
header('Content-Type: ' . $file['ContentType']);
echo $file['Body'];
?>
Run the Composer command to install s3 extension. composer require frostealth/yii2-aws-s3 ~1.0#stable
Open common/config/main.php file and add below code into "components" section. "s3bucket" => [ "class" => \frostealth\yii2\aws\s3\Storage::className(), "region" => "Your region", "credentials" => [ "key" => "your aws s3 key", "secret" => "your aws s3 secret", ], "bucket" => "your aws s3 bucket", "defaultAcl" => \frostealth\yii2\aws\s3\Storage::ACL_PUBLIC_READ, "debug" => false, // bool|array ],
Use below code to upload image on s3 $s3 = Yii::$app->get('s3bucket')->upload('upload image name', 'path of local folder where image located');
After uploading you get status code and image url. you can get like below $status = $s3["#metadata"]["statusCode"]; $imageUrl = $s3["#metadata"]["effectiveUri"];
I reimport my extension using composer,
and adding
require (\Yii::getAlias('#vendor/autoload.php'));
Somehow I got it working by adding 'autoload' in json composer
"autoload": {
"psr-4": {
"vendor\\aws\\" :""
}
}
and then run
php composer.phar dumpautoload
Was looking around for this for a few hours and only found other packages to solve the issue. Wanted to implement the AWS package directly. So from
Installed the latest aws-sdk via composer.
I am using
"aws/aws-sdk-php": "^3.259"
Make sure aws source and location is correct in the vendor/composer/autoload_psr4.php
'Aws\\' => array($vendorDir . '/aws/aws-sdk-php/src')
After that ran composer update as mentioned by #Karate_Dog
php composer.phar dumpautoload
I am attempting to use the thujohn/twitter package to get a live twitter feed on my site.
I got it working on my local server by using the tutorial found here but when I uploaded the changes to my digital Ocean server, I got the error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'Helpers' not found
Here are the steps I took - not much code:
I downloaded the package with artisan
config/app.php: added 'Thujohn\Twitter\TwitterServiceProvider', to the providers and 'Twitter' => 'Thujohn\Twitter\TwitterFacade' to the aliases
added app_path().'/classes', to the start/global.php file
I added a Helpers class to classes/helpers.php, which contains:
public static function twitterFeed($screen_name='screenName', $count='1', $include_retweets='false', $exclude_replies='true')
{
$twitterfeed = Cache::remember('twitterfeed', 30, function() use ($screen_name, $count, $include_retweets, $exclude_replies) {
return Twitter::getUserTimeline(
array(
'screen_name' => $screen_name,
'count' => $count,
'include_rts' => $include_retweets,
'exclude_replies' => $exclude_replies
)
);
})
;
if(!empty($twitterfeed)) {
return $twitterfeed;
}
else {
return array();
}
}
Put a view::share in my route file:
View::share('tweets', Helpers::twitterFeed('contractrsherpa', '1', false, true));
then looped through it in my view.
Finally, ran composer dump-autoload.
Seems pretty straightforward and works great locally. I uploaded everything to my liver server, ran composer dump-autoload, but still get the error "class 'Helpers' not found."
Any idea what I need to do to get this to work on the live site?
TIA
I am trying to install Amazon AWS SDK StreamWrapper on cPanel.
I have this code in my s3_Upload.php file:
<?php
require 'aws/aws.phar';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$s3Client= S3Client::factory(array(
'key' => "<key>",
'secret' => "<secret_key>"
));
$s3Client->registerStreamWrapper();
$s3Bucket = '<bucket_name>';
$s3Path = 's3://'.$s3Bucket;
if (file_exists($s3Path.'/<folder>/clip.mp4')) {
echo 'Clip exists!';
} else {
echo 'Clip doesnt exists!';
}
?>
and I have both the aws.phar file and extracted version of aws-sdk-php-master.zip.
Issue:
Whenever I try to go to www.example.com/s3_Upload.php it writes this error:
Fatal error: Class 'Phar' not found in /home/<user>/public_html/aws/aws.phar on line 17
It seems your PHP environment is missing PHP/PECL's Phar class. This is odd, because, according to the Phar Installation page, "The Phar extension is built into PHP as of PHP version 5.3.0.".
So either you need to make sure the Phar extension is installed, or you need to use the aws.zip.
Note: The aws.zip is not the same as the aws-sdk-php-master.zip you've mentioned. I assume what you have is just a download of the SDK source from GitHub. That zip file would not contain any of the SDKs dependencies like aws.phar and aws.zip do. To use the official aws.zip, please see Installing from the Zip from the AWS SDK for PHP User Guide.