Yii2 Azure Flysystem cannot save error - php

When I am uploading a file to the Azure FILE Storage I am getting the following error:
in
E:\WAMP\www\myweb\_protected\vendor\microsoft\windowsazure\WindowsAzure\Common\Internal\Http\Url.php at line 74 – WindowsAzure\Common\Internal\Validate::isTrue(false, 'Provided URL is invalid.')
E:\WAMP\www\allure\_protected\vendor\microsoft\windowsazure\WindowsAzure\Common\Internal\RestProxy.php at line 122 – WindowsAzure\Common\Internal\Http\Url::__construct('https://cG9rYXJuYXZpb282mGQ=.blo...')
The settings that I have in my config file is:
'filesystem' => [
'class' => 'creocoder\flysystem\AzureFilesystem',
'accountName' => 'azure-accname',
'accountKey' => 'some-long-key-A==',
'container' => 'azure-container',
],
and finally, the code I am calling to save the file is:
if($file = \yii\web\UploadedFile::getInstance($this, 'attachment'))
{
$stream = fopen($file->tempName, 'r+');
Yii::$app->filesystem->writeStream($file->name, $stream);
}
Some additional information that might be helpful
running on yii2 advanced framework
webserver: IIS 8.5 on Windows 2012
PHP 5.4.5
composer used for installation
its a azure file system - the error seems to throw error for blob.core.windows.net, where as I am saving data to file.core.windows.net. What changes should I do in config / settings?

According the source code at https://github.com/creocoder/yii2-flysystem/blob/master/src/AzureFilesystem.php#L62, it seems the package encrypt the storage info string into base64 encode before combine them into the connection string. Which makes the strange looking url format in your error message 'https://cG9rYXJuYXZpb282mGQ=.blo...'.
Please try to set the account info into following format:
...
'accountName' => base64_decode('azure-accname'),
'accountKey' => base64_decode('some-long-key-A=='),
...
Any further concern, please feel free to let me know.

Related

Laravel Vapor and Lavavel Excel queued imports failing. due to temp storage not existing Laravel 8 Vapor

When I am trying to run an import that implements chunk reading and queues I am receiving the following error from the vapor queue;
ErrorException: touch(): Unable to create file /tmp/storage/framework/laravel-excel/laravel-excel-7IEEz0rP7NORtp7N4NeOxuH0hlbM9JPR.csv because No such file or directory in /var/task/vendor/maatwebsite/excel/src/Files/RemoteTemporaryFile.php:97
Documentation On Laravel Excel says to set these value in config/excel.php
https://docs.laravel-excel.com/3.1/imports/queued.html#multi-server-setup
'temporary_files' => [
'local_path' => storage_path('framework/laravel-excel'),
'remote_disk' => 's3',
'force_resync_remote' => true,
My vapor yml file has the following storage set up all working fine with correct env values. for vapor and local development
storage: **correct bucket name**
Has anyone managed to get Queued imports working with Laravel Excel and Vapor, and if so how did you manage it? the documentation doesn't really explain what values I should use
Try to set local_path to the tmp dir in the config file
<?php
return [
'temporary_files' => [
'local_path' => sys_get_temp_dir(),
...
],
];

Laravel evaluates JPEG as of mime-type application/octet-stream but php and ubuntu correctly state image/jpeg

In a Laravel 7 application I am uploading images. In my last batch I uploaded roughly 600 jpegs and 80 of these jpegs failed to be uploaded becaus of a Laravel validation error. The other jpegs were uploaded successful.
I checked all these 80 jpegs manually via Ubuntu command line tool file and also via php-interactive-mode finfo. Both tell that the mime-type is image/jpeg.
But my code in Laravel
$this->validate($request, [
'file' => 'required',
'file' => 'file',
'file' => 'mime-types:image/jpeg'
]);
returns message: "The given data was invalid.", errors: {file: ["validation.mime_types"]}} beause the mime-type was evaluated to be application/octet-stream from Laravel.
I then thought okay, Laravel might do some special coding. Therefore I checked the source-code of Laravel at FileinfoMimeTypeGuesser.php and at FileBinaryMimeTypeGuesser.php. But Laravel obviously only either uses file -b --mime -- %s or new \finfo(\FILEINFO_MIME_TYPE, $this->magicFile); so nothing special at all.
And both code-options result in (as written before) image/jpeg when I use file on the Ubuntu command line or finfo in an interactive-mode php session for any of the above mentioned 80 jpegs which Laravel rejected.
Can anyone help me on this? How is Laravel determining the mime-type? Maybe there is a magic database in Laravel which I need to update?
Thanks in advance.

What can make weird changes into opcached framework code?

I encountered strange error with my php-fpm 5.6.30 with OPcache v7.0.6-dev on ubuntu server. I got error at /vendor/monolog/monolog/src/Monolog/Logger.php file concerning array_keys(static::$levels) code in it:
array_keys() expects parameter 1 to be array, object given
The static::$levels property is defined in the top of Logger.php file as array:
protected static $levels = array(
self::DEBUG => 'DEBUG',
self::INFO => 'INFO',
self::NOTICE => 'NOTICE',
self::WARNING => 'WARNING',
self::ERROR => 'ERROR',
self::CRITICAL => 'CRITICAL',
self::ALERT => 'ALERT',
self::EMERGENCY => 'EMERGENCY',
);
This code was installed via composer and never edited manually, so there is no reasons for the file to be changed.
When I look at my laravel.log, I see that something has changed the code behaviour, so lines at the log changed their format:
[2018-05-16 00:19:22] production.INFO: blabla
[2018-05-16 00:20:04] production.[object] (DateTimeZone: {"timezone_type":3,"timezone":"UTC"}): blablabla
The key fact is that when I opened the file using nano, added a comment line into it and saved, the bug disappears. It means that the wrong code was in the opcache, not in the code of the framework.
To conclude, the bytecode of Logger.php was somehow changed and php saw object with DateTimeZone objects in it rather than an array of strings.
The question is - how could the cached bytecode be changed without being totally crashed? What on earth can do this? Can high memory consumption lead to such unexpected changes?
We had the same issue in our project (php 5.6.30, opcache v7.0.6-dev). To solve the problem we analyzed the opcache settings and found that interned_strings_buffer was 4Mb. Raising this value to 64 Mb we solved the problem.

Configure Cakephp 2.6.0 with Redis Engine

I am trying to configure cakephp ver 2.6.0 to use redis engine by default. but somehow i am not able to make it work. any help will be highly appreciated.
Things Which i have tried so far..
Configured app/config folder 2 files , core.php and bootstrap.php. , according to the guidelines provided here in this blog configure cake with redis and this blog too Another cake-redis config setup
but i keep on getting errors like.
Fatal error: Uncaught exception 'CacheException' with message 'Cache engine session is not properly configured.' in C:\wamp\www\project\cakephp\cakephp_2.6.0\lib\Cake\Cache\Cache.php on line 181
CacheException: Cache engine session is not properly configured. in C:\wamp\www\project\cakephp\cakephp_2.6.0\lib\Cake\Cache\Cache.php on line 181
Any help will be highly appreciated.
I was having the same exact issue today while trying to setup CakePHP to use Redis as the cache engine.
Coincidentally, I also read the same setup instructions from the two blogs you linked to.
The reason was that I had copied pasted the Configure::write(...) code block from the Another cake-redis config setup blog post as it is and pasted it into the file without first commenting out the Configure::write(...) code block that was already in the core.php file.
I'm assuming that you have already successfully setup Redis on Windows and have installed the PHPRedis extension without any issues.
I am using the instructions from Another cake-redis config setup here.
In your app/Config/core.php file, comment out the following block: (this was starting at line 218 in my core.php)
Configure::write('Session', array(
'defaults' => 'php'
));
Instead, you can put this in: (You can change the values to suit your particular needs)
Configure::write('Session', array(
'defaults' => 'cache',
'timeout' => 100,
'start' => true,
'checkAgent' => false,
'handler' => array(
'config' => 'session'
)
));
After this, change the value of $engine to 'Redis', so it becomes:
$engine = 'Redis';
And then, put this code in, I put this in at the very end of the file: (Again, your values can be different depending on what your setup is)
Cache::config ('session', array (
'Engine' => $engine,
'Prefix' => $prefix . 'cake_session_',
'Duration' => $duration
));
And that's it. You're done! No need to change anything else.
To make sure that Redis is working properly with CakePHP, I ran the RedisEngine Test Suite that comes with CakePHP. You need to have PHPUnit installed for this to work.
It can be accessed via http://your-cakephp-project/test.php
Click on 'Tests' under Core and then click on 'Cache/Engine/RedisEngine'
If everything is working successfully, you should see all the tests pass.
Alternatively, you can use redis-cli at the command prompt to confirm that Redis is storing keys properly.
Once you have logged in by typing redis-cli, type KEYS *
This should give you a list of keys related to your CakePHP setup.
An example would be the "myapp_cake_core_object_map" key.
Hope this helps.

Set up Google API on ZF2/PHP - Cannot connect to server

I am trying to connect to the google API from a localhost, but keep on receiving an exception (key changed - in text below).
Warning: file_get_contents(compress.zlib://https://www.googleapis.com/books/v1/volumes?q=Henry+David+Thoreau&filter=free-ebooks&key=bItatTTTTT7amAHYSaROTTTTTbtttuuuuuuuu) [function.file-get-contents]: failed to open stream: operation failed in C:\zendProject\zf2\vendor\google\apiclient\src\Google\IO\Stream.php on line 115
The code I am using in my browser comes straight from the API Guide and reads:
$client = new \Google_Client();
$client->setApplicationName("rent");
$service = new \Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
I think my problems relate to the config file, and that fact I am working off the localhost development server.
'Google_Auth_OAuth2' => array(
'application_name' => 'www.example.com',
'client_id' => '4498xxxxx061-3333xxxx9pjcpkbqhoxxxxxxxxxxx.apps.googleusercontent.com',
'client_secret' => '8xxxxxxxxx333xxxxxxxxx',
'redirect_uri' => 'http://localhost',
'developer_key' => 'AxxxxxxzBjpxxxxxaxxxxxxZxxx1xxxxx',
In the new developer console I have created a new client ID for the project and inserted the "Client_id", "Client_secret", etc.
I have also enabled the relevant APIs for Calenders and Books.
I have tested my API key on the URL I found for google fonts - so I am sure I have the right developer key.
I suspect the issue may be around the local host in uri fields, what do I need to put in here?
Does anyone know what I am doing wrong.
UPDATE: I found a post that suggested getting the HTTP response code here:
The response from the server is 304 - not sure if this helps
UPDATE: #Carlos Roubles - was correct I was using the incorrect version. Just in case anyone else runs into this issue - the composer information on the google website appears to be incorrect.
I previously used "google/apiclient": "1.0." this appears in the google documentation. I have now tried "google/apiclient": "1." and this seems to have fixed the problem.
Thats a problem with file_get_contents rather that with the api.
Most people changes file_get_contents to CURL for accesing remote files.
Anyways, i was checking the library and i cannot find any call to file_get_contents in all the stream.php file
https://github.com/google/google-api-php-client/blob/master/src/Google/IO/Stream.php
and in line 115, what we have is a commented line, so what comes to my mind is that yu are not using the last version of the library. Also, i see that in this version they make the request with fopen.
So you can try to update it, and probably this fixes the issue

Categories