Https urls in Laravel - Rackspace with Filesystem - laravel

I am using filesystem package without problems for upload and download files to rackspace. According to docs on how to obtain the file url I do:
$content = fopen('logo.png', 'r+');
\Storage::disk('disk_temp')->put('logos/logo.png', $content);
$url = \Storage::disk('disk_temp')->url('logos/logos.png');
Works good. But, this url is http:// version. How to obtain the secure version like https:// if I am using rackspace vendor? Here my config:
'disk_temp' => [
'driver' => 'rackspace',
'username' => env('RS_USER'),
'key' => env('RS_API'),
'container' => 'disk_temp',
'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
'region' => env('RS_REGION', 'DFW'),
'url_type' => 'publicURL',
],
Years before, I used Open Cloud successfully, obtaining the URL as
$file = \OpenCloud::container('cdn')->uploadObject($filename, $content);
$url = (string) $file->getPublicUrl(UrlType::SSL);
Just to know if possible doing the same from laravel itself. Thank you in advance.

Related

Guzzle 7 + Guzzle-cache-middleware

I'm using Guzzle 7 to grab content from an external API with basic authentication. It works fine. Now I'd like to integrate cache management. So i've tried to use this plugin: [Guzzle-cache-middleware][1] and I can't make it working correctly. I can get API response and my desired content but the cache directory is not populated.
I've searched all around the web but I can't figure this out. Could you please tell me how to solve this? Here is my code:
$userName = "xxxxxxx";
$password = "yyyyyyyyyyy";
require_once './vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Kevinrob\GuzzleCache\CacheMiddleware;
use Kevinrob\GuzzleCache\Strategy\PublicCacheStrategy;
$stack = HandlerStack::create();
$cache = new CacheMiddleware();
$stack->push($cache, '/home/xxxx/xxxxx/guzzle2/cache');
$client = new Client([
'handler' => $stack,
'base_uri' => 'https://api.xxxxx.com/xxx/',
"timeout" => 30.0,
]);
$json = $client->get('zzzzzz.json', [
'auth' => [
$userName,
$password
]
]);
var_dump($json->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
Output:
string(4) "MISS"
So API result is different from cache. But headers params (ETag and Last-Modified) are still unchanged and my cache folder is still blank.
Thank you for your help!

Laravel FTP - Root path for windows server

I am trying to upload a file from my local to FTP server using laravel
'ftp' => [
'driver' => 'ftp',
'host' => env('FTP_HOST'),
'username' => env('FTP_USERNAME'),
'password' => env('FTP_PASSWORD'),
'port' => '21',
'passive' => false,
'root' => 'c:/POSActiveAutoInsert/WEBSales_In/' // for example: /var/www/html/dev/images
//
],
In my controller
Storage::disk('ftp')->put('test.txt', $file);
But when I run this, it says
Root is invalid or does not exist: c:/POSActiveAutoInsert/WEBSales_In/
I have tried FTP using Filezilla it works fine
The FTP account I am using takes you directly to c:/POSActiveAutoInsert/WEBSales_In/ this folder. This WEBSales_In is the root folder for this FTP user that I am using. Can't figure out what the root path would be, or am I doing something wrong other than this.
Cheers
You can try this in your controller
$path = $request->your_variable_name->storeAs('text', '$file', ['disk' => 'ftp']);

Send Mail Using Lumen

Mail.php
return [
'driver' =>'smtp',
'host' => 'smtp.gmail.com',
//'port' => 587,
'port' =>465,
//'encryption' =>'tls',
'encryption' =>'ssl',
'username' => 'xxxxxxxx#gmail.com',
'password' => 'xxxxxxx',
// 'sendmail' => '/usr/sbin/sendmail -bs',
'sendmail' => '/usr/sbin/sendmail -t',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
Controller
$data = []; // Empty array
Mail::send('email.credentials', $data, function($message)
{
$message->to('xxxxxx#gmail.com', 'Jon Doe')->subject('Welcome!');
});
Error
Swift_TransportException Connection could not be established with host
smtp.gmail.com [A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond.
I Tried...
Change ssl / tls
Change the ports
Add "guzzlehttp/guzzle": "~5.3|~6.0" in composer.json
Add a new line in StreamBuffer.php
$options = array_merge($options, array('ssl' => array('verify_peer' =>
false,'verify_peer_name' => false,'allow_self_signed' => true )));
Please help .
Thank you.
1. Require illuminate/mail
Make sure you’re using the same version as your underlying framework (i.e. if you’re on Lumen v. 5.3, use composer require illuminate/mail "5.3.*").
composer require illuminate/mail "5.5.*"
2. Set up Lumen bootstrap/app.php
First, open your bootstrap.php and uncomment the following lines:
$app->withFacades();
$app->register(App\Providers\AppServiceProvider::class);
Also, add the following line below the last line you uncommented:
$app->configure('services');
This will allow you to define a ‘services’ config file and setup your mail service. Now I know that normally configuration is done in the .env file with Lumen, and we’ll use that shortly, but first we’ll need to write a small config file to map to the .env file.
3. Create your configuration files
Create a new folder at the root level of your install called config(if it doesn’t already exist). In the config folder, create two new files, one named services.php and another named **mail.php**.
In the services.php file paste the following:
<?php
return [
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
];
Lastly, add the following to your .env file:
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=<your-mailgun-domain>
MAILGUN_SECRET=<your-mailgun-api-key>
Make sure you replace those sneaky placeholders with your actual key and domain. If you’re not using Mailgun, you can always use the other mail providers Mail comes with; have a look at the docs if you plan on using a different provider, they are all easy to set up once you’re at this point.
4. Send Email!
To send an email, use one of the following in your classes (depending on your preference):
use Illuminate\Support\Facades\Mail;
$data = []; // Empty array
Mail::send('email.credentials', $data, function($message)
{
$message->to('xxxxxx#gmail.com', 'Jon Doe')->subject('Welcome!');
});
Finally, don’t forget to read the Laravel Mail docs for more info on how to use this great library.
Have you turned on 2 layers security in your Google account (email address you config in .env file) which uses to send email.

How to Submit File in Leads Document In Vtiger by Web Services in Laravel 5

I am Trying to Submit/Create new Leads[data] in Vtiger via Web service in Laravel 5. For that I use WSClient in Laravel.
My Code is in Controller is :
$url = http://xxxx.com;
$config = [
'auth' => [
'username' => 'xxxx',
'accesskey' => 'xxxx'
],
'testing' => []
];
$wsclient = new WSClient($url, $config);
$create = $wsclient->createObject('Leads', array(
'firstname' => 'My Firstname',
'lastname'=>'My Lastname',
'phone'=>'MyPhone',
'email'=>'email#email.com',
'description'=> 'abcdabcd123',
'assigned_user_id'=>1,
));
It Works Fine when I just Create Leads. But Now I need to Submit File in Leads Document So I use follow Code But Not Works
$create = $wsclient->createObject('Documents', array(
'notes_title' => 'Leads Pdf File',
'file'=>'http://website/pdffile.pdf',
'assigned_user_id'=>1,
));
It Works But File not Uploads
How can I Submit File in Leads Document in Vtiger by Web services from Laravel by WSClinet ?
Your code is correct but currently Vtiger web services do not offer the possibility to upload the file on the server.
If you have the file hosted on your server you can create the document as:
$create = $wsclient->createObject('Documents', array(
'notes_title' => 'Leads Pdf File',
'file'=>'http://website/pdffile.pdf',
'filelocationtype' => 'External', //This will create a link to your server from the crm
'assigned_user_id'=>1,
));
Or you can extend Vtiger webservices code so it's download and import the file.

Integrating elfinder with s3 in Laravel 4.2

I am trying to integrate elfinder in Laravel 4.2 using barryvdh/laravel-elfinder package. This works perfectly for the local file system. I need to integrate it with AWS S3. For that I have used flysystem driver. In this packages config file, I have defined root like this
'roots' => [
[
'driver' => 'Flysystem',
'adapter' => new \League\Flysystem\AwsS3v2\AwsS3Adapter( \Aws\S3\S3Client::factory(array(
'key' => 'key',
'secret' => 'secret',
'region' => 'us-east-1',
)), 'bucket_name', '')
]
],
But this doesnt seem to work. I get this error {"error":["errConf","errNoVolumes"]}
Have anyone successfully done this before. Please help me.

Resources