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

How to upload to Google Drive directly without uploading file to server #87

Open
sushilsth opened this issue Jul 25, 2020 · 3 comments
Open

Comments

@sushilsth
Copy link

Hi,

I want to upload file directly from client to Google drive.

I can upload to google drive after uploading to the server and then to drive.

Here is what I tried.

 if ($request->hasFile('file')) {
       $files = $request->file('file');
       for ($i = 0; $i < count($files); $i++) {
            if ($files[$i]->isValid()) {
                   $attachment = $files[$i];
                   $fileContent = File::get($attachment);
                  $name = explode('.', $attachment->getClientOriginalName());
                  $fileName = $name[0] . '.' . $attachment->getClientOriginalExtension();
                  $fileNameUnique = $name[0] . '_' . date('Ymdhis') . '.' . $attachment->getClientOriginalExtension();
                   //get drive folder
                  $homework_dir = $contents->where('type', '=', 'dir')
                                                                    ->where('filename', '=', 'homework')
                                                                    ->first();
                  $dir = '/' . $homework_dir["path"] . '/';
                  Storage::drive('google')->put($homework_dir["path"] .  '/' . $filename, $fileContent );
      }}}

Is this something possible?

Another approach is I tried to upload file to the server first and then moving to Google Drive by using Laravel Queue. All went correctly except I am only able to upload upto 4 images to the google drive. Suppose, I upload 6 images then the first four files in the loop gets uploaded and rest donot gets upload. Is this somethings that I need to makes changes to config file?

Thank you.

@ivanvermeyen
Copy link
Owner

ivanvermeyen commented Jul 25, 2020

Hi,

Take a look here: #61

For multiple files, I always use some sort of JS drag and drop package that would send files one by one even if you select multiple.

@sushilsth
Copy link
Author

Thank you for the reply. I tried the solution mentioned in #61 https://laravel.com/docs/5.8/requests#storing-uploaded-files. Upload works fine for only 1 file. I want to upload multiple files but I got the below error

 The stream or file "/var/www/storage/logs/laravel-2020-07-26.log" could not be opened: failed to open stream: Permission denied

Any Idea?

@ivanvermeyen
Copy link
Owner

Are the permissions set correctly?

Directory Permissions
After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run. If you are using the Homestead virtual machine, these permissions should already be set.

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

2 participants