Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload of images to Google Drive is killing my bandwidth/freezes my site #81

Closed
Arturexe opened this issue Aug 15, 2022 · 2 comments
Closed

Comments

@Arturexe
Copy link

Arturexe commented Aug 15, 2022

When executing this line of code:

Storage::disk('google')->put($imageId, base64_decode($src));

my whole app becomes unresponsive. When opening a new browser tab, the page doesn't load before the upload to drive is finished. I assume that the upload to drive burns up my whole upload bandwidth. Is there a throttle option or another way to prevent this from happening?

I'm using drive to store and retrieve images.

Here's my GoogleDriveServiceProvider.php:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Storage;
use Google\Client;
use Google\Service\Drive;
use Masbug\Flysystem\GoogleDriveAdapter;
use League\Flysystem\Filesystem;
use Illuminate\Filesystem\FilesystemAdapter;


class GoogleDriveServiceProvider extends ServiceProvider
{

    public function register()
    {
        //
    }

    public function boot()
    {
        try {
            Storage::extend('google', function($app, $config) {
                $options = [];

                if (!empty($config['teamDriveId'] ?? null)) {
                    $options['teamDriveId'] = $config['teamDriveId'];
                }

                $client = new Client();
                $client->setClientId($config['clientId']);
                $client->setClientSecret($config['clientSecret']);
                $client->refreshToken($config['refreshToken']);

                $service = new Drive($client);
                
                $adapter = new GoogleDriveAdapter($service, $config['folder'] ?? '/', $options);
                $driver = new Filesystem($adapter);

                return new FilesystemAdapter($driver, $adapter);
            });
        } catch(\Exception $e) {
            return $e->getMessage();
        }
    }
}
@erikn69
Copy link
Contributor

erikn69 commented Aug 15, 2022

Maybe try this 8afb3ff

@masbug
Copy link
Owner

masbug commented Aug 16, 2022

@Arturexe
First of all, all of the below is out of scope of "issues" section.

When opening a new browser tab, the page doesn't load before the upload to drive is finished.

This is normal. The whole operation is synchronous. If you want to make it async then you need to create a worker and send the upload job to it.

I assume that the upload to drive burns up my whole upload bandwidth. Is there a throttle option or another way to prevent this from happening?

Of course it does. It performs a series of web requests.
You could try to set global "curl" settings and try to throttle the bandwidth that way. Hint: https://curl.se/libcurl/c/CURLOPT_MAX_RECV_SPEED_LARGE.html

@masbug masbug closed this as completed Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants