Remote Upload To Google Drive by DRIVE API - php

How to upload a file to Google Drive using the API by a url(Remote Upload)? I read the doc and I did not find any option like DropBox where save_url() can be used to remote upload.
But, there are a lot of sites which allows remote upload to Google Drive, so it must be possible.

You may refer with this tutorial on how to directly upload files from the web to Google Drive without saving them completely on the server before. This is useful to upload files, which are bigger than the storage available on the server.
How to use it:
Rename "credentials/oauth-credentials_EXAMPLE.json" to "credentials/oauth-credentials.json"
Download your oauth2 credentials in the google developer console and copy it in it
Call the "index.php" from the console ("php index.php")
Follow the messages in the console window
Create pull requests to help with the development
Hope this helps!

Related

Try to view all shared files, but shows only opened before

I'm developing PHP script, using Google drive API
It's work fine, but shows shared files that only opened before through google drive interface...
Same results got with
https://developers.google.com/drive/v3/reference/files/list
Why I don't see new shared files and view only Recent files?
How can I view newest files on Shared with me section?
Thank you in advance.
To debug this, here's what you can do:
Share a file using emailA in the Drive web app to your emailB. Then, log your emailB to Drives list explorer. The file should appear there as I've tested this myself. If it DOESN'T, the problem is not Drive API.
Either you've not properly shared the file in your code implementation or you need to re-run your PHP code.

PHP Google Drive Simple Upload

I am new here and newbie in Google Drive thing. I managed to follow and install Google Drive v3. Now, I am stuck as to how can I make a simple PHP code that will upload a text file to my Google Drive. I need a simple PHP code / guide on how to upload a small text file. Please help.
Thanks in advance.
If you want to know how to upload file, then you can check the DRIVE API documentaion for that.
Here you can find 3 options on how to upload file.
simple upload
multipart upload
resumable upload
Just visit the above link to know more about them.
For the PHP code that you want, then you can check the answer in this SO question.
Just remember that you need to set <YOUR_REGISTERED_REDIRECT_URI> to the document to authenticate it.
For more information or other way to upload file using service account, check this SO question.
If you want to understand the process of file upload on google drive.
There is a repository on GitHub on how to authenticate and upload files on google drive using Google Drive API in PHP. You can give it a try.
https://github.com/SM4991/php-google-drive

How do I copy & save GDrive files to my server using Google Apps Script / PHP?

I am working to create a script that scans our company Google Drive folders and copies any new files into a Repository directory on my server.
So far I can connect to GDrive, read all files, edit files, but I am unable to download via PHP. copy() file_get_contents() file_put_contents() etc. Are not working.
I imagine the solution is to use Google Apps Script to download and copy the file to my server directory, but I do not see the correct class.methods in the documentation.
How can I copy a GDrive file to my server using Google Apps Script?
You could run some code through Google Apps Script to upload the files to your server. In that case you need to use UrlFetchApp.fetch, which despite its name can also do an HTTP POST with arbitrary data. There is an example for uploading files in the API documentation.
https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app

Download file from Internet and uploading to GDrive

So far, I've built a PHP script that downloads to a remote server of mine a file from Internet, provinding its URL (I've used this piece of code to download to the server).
Now I would like to upload the downloaded file on Google Drive using its API.
My question is: Is there a way to download the file directly to Google Drive, without using the server? Or I am forced to download the file first to the server and then upload it to Google Drive?
Thank you
I doubt if you can 'make' google drive get file from an external location...
However you do have an option to create a shortcut to the external file, if that suits you.
Also, If you wish continue direct upload you may refer this.
As far as I know the API doesn't allow to push files from another referer than the one that's calling the API. So, long story short:
First you need to download the file to your server, then upload it to gDrive from your server.
Read here more: https://developers.google.com/drive/examples/php#saving_files
Or here: https://developers.google.com/drive/manage-uploads

Online file storage logic

I want to develop a website like file manager. Where user register and will get fix disk space lets say 20MB.
Now user can upload their pdf, doc, txt, jpeg etc files upto their disk limit.
I can develop upto this using PHP.
Now below is my issue:
1) If user's files are corrupted they can rollback their folders before 2-3 days.
Files must be secure and safe from viruses as users are uploading their important documents.
Is there any 3rd party storage server who provides such facility?
2) Also all files should be previewed from browser.
I am using Google doc viewer. Is is good and safe way to preview file in browser?
But google links are accessible from all, I need to add some restrictions as file can be viewed only by their owner.
I know it's a major task, but i just need some sort of logic. Please share your thoughts.
Thanks.
Any cloud storage service can be used for this. You'll get HDD space. There is not storage server who provides revision control system for this. You can use git, svn for this though. But as the files are binary you can not get full facility of these tools.
How file will be previewed depends on you. If you use PHP you make the site and at the backend you use the API to interact with the storage service. Google doc is not an option for this if you use PHP. Also note Google links can be made private.
I suggest you this,
Find a cloud storage service and use the storage in your server. Any will do.
Create UI using PHP and control the access using PHP too.
Manipulate files in your server directly or in 3rd party storage server via API
Use a revision control system to track the changes. And use its API in PHP end.
Some cloud storage service
Amazon S3. It also supports Versioning.
Google Cloud Storage
Microsoft Azure
Try Microsoft SkyDrive or Google Drive or Dropbox

Categories