Help Implementing yii2-storage

I came across

I’ve manage to install it, and I believe I’ve configured it properly in my config. That said, I can’t remotely figure out how to use it.

I do not understand what in his samples is controller, model, view. Since the file is being upload to, in my case Azure, how I relate this in a model.

I know I’m asking a lot, but is there anyone that could offer a functional sample to learn from?

1 Like

There are examples of usage there as I can see. What is the problem?

1 Like

I can’t relate them to implement them.

I have a fully functional MVC for managing files and wanted to convert it from local storage to Azure, so I thought I could use this extension. But I can’t figure out how to implement it in the least.

In his example he defines ’ storageAzure’, but then uses ‘storage’?

In my controller, I tried

            // Kartik FileInput Approach
            $webFile = \yii\web\UploadedFile::getInstance($model, 'webFile');
            if ($webFile !== null) {
                $fileManager = Yii::$app->storageAzure->getFileManager();
                $azureReponse = $fileManager->upload($webFile);

which returns 1, but there’s nothing in the Azure container.

You’ll say, that not like his example. I tried

Yii::$app->storageAzure->save($fileManager);

just like his example and get an ‘Calling unknown method’ error

Just as much as using

Yii::$app->storage->save($fileManager);

returns an ‘Unknown Property’ error.

I also looked at his example for a form field, but normally I use $model, some fieldname, and am not sure how to relate his example to the existing model/…

I’m just lost, between what is what, how it should be used in the Model vs the Controller vs the View… How to configure the variables, is it storage or azureStorage, …

1 Like

The name in Yii::$app->xxx should match the name you set in the configuration, but I cannot help with the rest, not sure if this package works properly or maybe some other things are involved like configuration on your side. I’m afraid you have to figure it out (or perhaps ask the package author).

1 Like

I’ve already configured Azure, have the proper name, key, …

I’ve already contacted the author.

1 Like

I’m close, maybe someone has an idead

I’ve got

           $storage = new AzureStorage([
            'config' => [
                'accountName' => 'MyAccntName',
                'accountKey' => 'MyKey',
                'container' => 'MyContainerName',
                'extensions' => 'pdf, jpg, jpeg, gif, png, bmp, log, ini, txt, xls, xlsx, doc, docx'
            ],
        ]);            
           $fileManager = $storage->getFileManager();
            // $fileManager->uploadedFile->name . ' ' . $fileManager->uploadedFile->type
            if (null !== $fileManager->uploadedFile) {
                $azureReponse = $storage->save($fileManager);
            } else {
                $azureReponse = false;
            }

I have confirmed that the basics work in the sense that

$fileManager->uploadedFile->name
$fileManager->uploadedFile->type

return the proper file information, so fileManager is populated. Yet when I perform the

$storage->save($fileManager);

I get a “‘blob’ can’t be NULL or empty.” error. Can anyone offer any insight, ideas?