Is there any URL I could use to directly upload to Google Drive? For example, I have a file on my server http://example.com/file.doc
and I want to upload it to Google Drive with something like: http://google.com/?upload=http://example.com/file.doc
What's the approach to do this?
How about this workaround? Unfortunately, there are no URLs for directly uploading files without authorization on Google API. So I propose a workaround. I thought that this method may be easy for achieving what you want to do. Please think of this as one of several answers.
I think that using Web Apps, you can achieve your what you want to do. The flow of this workaround is as follows.
Flow :
1. Sample script
Please run
doGet(e)
. By this, although an error occurs, the authorization process can be done.2. Deploy Web Apps.
https://script.google.com/macros/s/#####/exec
.3. Upload a file from URL
url=http://example.com/file.doc
.file.doc
by accessing this URLhttps://script.google.com/macros/s/#####/exec?url=http://example.com/file.doc
using your browser.Note :
If this was not useful for you, I'm sorry.
Edit :
I understand that you want to upload files from URL using php and javascript (I used jQuery here.). If my understanding is wrong, please tell me.
doGet(e)
of Google Apps Script is required to use these script. At first, please copy and pastedoGet(e)
and deploy Web Apps. For both script, the file ID of created file on Google Drive is returned as the response.Upload by php
Upload by jQuery
References :
Edit 2 :
When you want to make users upload files to own Google Drive, please deploy Web Apps by the following flow.
Flow :
1. Sample script
Please run
doGet(e)
. By this, although an error occurs, the authorization process can be done.2. Deploy Web Apps.
https://script.google.com/macros/s/#####/exec
.3. Upload a file from URL
url=http://example.com/file.doc
.file.doc
by accessing this URLhttps://script.google.com/macros/s/#####/exec?url=http://example.com/file.doc
using your browser.https://script.google.com/macros/s/#####/exec?url=http://example.com/file.doc
, the login screen to Google is displayed.file.doc
is uploaded to user's Google Drive. Because the script is run as each user.Note :
https://script.google.com/macros/s/#####/exec?url=http://example.com/file.doc
as a link.Edit 3:
In the case of use of Web Apps, when
<div class="google-upload" data-url="http://example.com/file.doc">
is used, the sample script is as follows.When users click
Upload
,file.doc
is uploaded to user's Drive. In order to use this sample script, please use the URL retrieved by deploying Web Apps using above "Edit 2".In this case, the login screen is displayed to each user. Users are required to authorize to use APIs after login by click the button on the screen. Is this what you want?
Take a look at Drive Uploader
https://driveuploader.com/
you can create your own uploader and have a unique URL for the same which can be distributed among your users.
Hope it helps