Laravel Google drive integration “masbug/flysystem-google-drive-ext”: “^2.3.0” package is not working for laravel 11

Laravel Google drive integration “masbug/flysystem-google-drive-ext”: “^2.3.0” package is not working for laravel 11

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
namespace AppAdminControllers;
use AppAdminAdminController;
use IlluminateSupportFacadesStorage;
use MasbugFlysystemGoogleDriveGoogleDriveAdapter;
use MasbugFlysystemGoogleDriveGoogleDriveServiceProvider;
class GoogleDriveController extends AdminController
{
protected $client;
protected $folder_id;
protected $service;
protected $adapter;
protected $serviceProvider;
protected $ClientId = '###';
protected $ClientSecret = '###';
protected $refreshToken = '###';
public function __construct()
{
$this->client = new Google_Client();
$this->client->setClientId($this->ClientId);
$this->client->setClientSecret($this->ClientSecret);
$this->client->refreshToken($this->refreshToken);
$this->service = new Google_Service_Drive($this->client);
$this->folder_id = '1zQA5vLXEOnDVQ9ePPKfyiXUPbPxfJhT_';
$this->adapter = new GoogleDriveAdapter([
'clientId' => $this->client->setClientId($this->ClientId),
'clientSecret' => $this->client->setClientSecret($this->ClientSecret),
'refreshToken' => $this->client->refreshToken($this->refreshToken),
$this->service = new Google_Service_Drive($this->client),
]);
$this->serviceProvider = new GoogleDriveServiceProvider($this->adapter);
// Set the folder ID
$this->folder_id = '1zQA5vLXEOnDVQ9ePPKfyiXUPbPxfJhT_';
}
public function create_folder_in_parent($folderName, $parentFolderID)
{
$fileMetadata = [
'name' => $folderName,
'parents' => [$parentFolderID],
'mimeType' => 'application/vnd.google-apps.folder',
];
$folder = $this->serviceProvider->createDirectory($folderName, $parentFolderID);
return $folder['id'];
}
public function check_if_folder_exists($folderName, $folderID)
{
$folders = $this->serviceProvider->listContents('/', true);
foreach ($folders as $folder) {
if ($folder['type'] == 'dir' && $folder['basename'] == $folderName) {
return true;
}
}
return false;
}
public function upload_image($todayFolderID, $imageToBeUploaded, $imageName)
{
$result = $this->serviceProvider->write($todayFolderID.'/'.$imageName, $imageToBeUploaded);
return $result;
}
public function getShareableLink($fileID)
{
$file = $this->serviceProvider->getMetadata($fileID);
return $file['url'];
}
protected function remove_duplicated($fileName)
{
$files = $this->serviceProvider->listContents('/', true);
foreach ($files as $file) {
if ($file['type'] == 'file' && $file['basename'] == $fileName) {
$this->serviceProvider->delete($file['path']);
}
}
}
public function upload_files()
{
$files = Storage::files();
foreach ($files as $file) {
$this->remove_duplicated($file);
$read = Storage::get($file);
$this->upload_image($this->folder_id, $read, basename($file));
Storage::delete($file);
}
}
public function files_count()
{
$files = $this->serviceProvider->listContents($this->folder_id, true);
return count($files);
}
}
</code>
<code><?php namespace AppAdminControllers; use AppAdminAdminController; use IlluminateSupportFacadesStorage; use MasbugFlysystemGoogleDriveGoogleDriveAdapter; use MasbugFlysystemGoogleDriveGoogleDriveServiceProvider; class GoogleDriveController extends AdminController { protected $client; protected $folder_id; protected $service; protected $adapter; protected $serviceProvider; protected $ClientId = '###'; protected $ClientSecret = '###'; protected $refreshToken = '###'; public function __construct() { $this->client = new Google_Client(); $this->client->setClientId($this->ClientId); $this->client->setClientSecret($this->ClientSecret); $this->client->refreshToken($this->refreshToken); $this->service = new Google_Service_Drive($this->client); $this->folder_id = '1zQA5vLXEOnDVQ9ePPKfyiXUPbPxfJhT_'; $this->adapter = new GoogleDriveAdapter([ 'clientId' => $this->client->setClientId($this->ClientId), 'clientSecret' => $this->client->setClientSecret($this->ClientSecret), 'refreshToken' => $this->client->refreshToken($this->refreshToken), $this->service = new Google_Service_Drive($this->client), ]); $this->serviceProvider = new GoogleDriveServiceProvider($this->adapter); // Set the folder ID $this->folder_id = '1zQA5vLXEOnDVQ9ePPKfyiXUPbPxfJhT_'; } public function create_folder_in_parent($folderName, $parentFolderID) { $fileMetadata = [ 'name' => $folderName, 'parents' => [$parentFolderID], 'mimeType' => 'application/vnd.google-apps.folder', ]; $folder = $this->serviceProvider->createDirectory($folderName, $parentFolderID); return $folder['id']; } public function check_if_folder_exists($folderName, $folderID) { $folders = $this->serviceProvider->listContents('/', true); foreach ($folders as $folder) { if ($folder['type'] == 'dir' && $folder['basename'] == $folderName) { return true; } } return false; } public function upload_image($todayFolderID, $imageToBeUploaded, $imageName) { $result = $this->serviceProvider->write($todayFolderID.'/'.$imageName, $imageToBeUploaded); return $result; } public function getShareableLink($fileID) { $file = $this->serviceProvider->getMetadata($fileID); return $file['url']; } protected function remove_duplicated($fileName) { $files = $this->serviceProvider->listContents('/', true); foreach ($files as $file) { if ($file['type'] == 'file' && $file['basename'] == $fileName) { $this->serviceProvider->delete($file['path']); } } } public function upload_files() { $files = Storage::files(); foreach ($files as $file) { $this->remove_duplicated($file); $read = Storage::get($file); $this->upload_image($this->folder_id, $read, basename($file)); Storage::delete($file); } } public function files_count() { $files = $this->serviceProvider->listContents($this->folder_id, true); return count($files); } } </code>
<?php

namespace AppAdminControllers;

use AppAdminAdminController;
use IlluminateSupportFacadesStorage;
use MasbugFlysystemGoogleDriveGoogleDriveAdapter;
use MasbugFlysystemGoogleDriveGoogleDriveServiceProvider;

class GoogleDriveController extends AdminController
{
    protected $client;

    protected $folder_id;

    protected $service;

    protected $adapter;

    protected $serviceProvider;

    protected $ClientId = '###';

    protected $ClientSecret = '###';

    protected $refreshToken = '###';

    public function __construct()
    {

        $this->client = new Google_Client();
        $this->client->setClientId($this->ClientId);
        $this->client->setClientSecret($this->ClientSecret);
        $this->client->refreshToken($this->refreshToken);
        $this->service = new Google_Service_Drive($this->client);
        $this->folder_id = '1zQA5vLXEOnDVQ9ePPKfyiXUPbPxfJhT_';

        $this->adapter = new GoogleDriveAdapter([
            'clientId' => $this->client->setClientId($this->ClientId),
            'clientSecret' => $this->client->setClientSecret($this->ClientSecret),
            'refreshToken' => $this->client->refreshToken($this->refreshToken),
            $this->service = new Google_Service_Drive($this->client),
        ]);

        $this->serviceProvider = new GoogleDriveServiceProvider($this->adapter);

        // Set the folder ID
        $this->folder_id = '1zQA5vLXEOnDVQ9ePPKfyiXUPbPxfJhT_';
    }

    public function create_folder_in_parent($folderName, $parentFolderID)
    {
        $fileMetadata = [
            'name' => $folderName,
            'parents' => [$parentFolderID],
            'mimeType' => 'application/vnd.google-apps.folder',
        ];

        $folder = $this->serviceProvider->createDirectory($folderName, $parentFolderID);

        return $folder['id'];
    }

    public function check_if_folder_exists($folderName, $folderID)
    {
        $folders = $this->serviceProvider->listContents('/', true);

        foreach ($folders as $folder) {
            if ($folder['type'] == 'dir' && $folder['basename'] == $folderName) {
                return true;
            }
        }

        return false;
    }

    public function upload_image($todayFolderID, $imageToBeUploaded, $imageName)
    {
        $result = $this->serviceProvider->write($todayFolderID.'/'.$imageName, $imageToBeUploaded);

        return $result;
    }

    public function getShareableLink($fileID)
    {
        $file = $this->serviceProvider->getMetadata($fileID);

        return $file['url'];
    }

    protected function remove_duplicated($fileName)
    {
        $files = $this->serviceProvider->listContents('/', true);

        foreach ($files as $file) {
            if ($file['type'] == 'file' && $file['basename'] == $fileName) {
                $this->serviceProvider->delete($file['path']);
            }
        }
    }

    public function upload_files()
    {
        $files = Storage::files();

        foreach ($files as $file) {
            $this->remove_duplicated($file);
            $read = Storage::get($file);
            $this->upload_image($this->folder_id, $read, basename($file));
            Storage::delete($file);
        }
    }

    public function files_count()
    {
        $files = $this->serviceProvider->listContents($this->folder_id, true);

        return count($files);
    }
}

I upgrade laravel 6 to laravel 10

in laravel 10 it is not working.

Please provide me better solution for it.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật