-
Create a Google Cloud Platform Project:
- Go to the Google Cloud Console: https://console.cloud.google.com/
- Create a new project or select an existing project.
-
Enable the Google Drive API:
- In your Google Cloud Console project, navigate to the API Library.
- Search for "Google Drive API" and enable it.
-
Create OAuth 2.0 Credentials:
- In the Google Cloud Console, go to the "Credentials" section.
- Click the "Create Credentials" button and select "OAuth client ID."
- Choose "Web application" as the application type.
- Provide a name for your OAuth 2.0 client ID.
- Add the following redirect URIs:
https://your-worker-subdomain.your-subdomain.workers.dev/_oauth
https://your-worker-subdomain.your-subdomain.workers.dev/oauth2callback
Replaceyour-worker-subdomain
andyour-subdomain
with your actual Cloudflare Worker subdomain and domain.
- Click "Create" to generate your OAuth 2.0 client ID and client secret.
-
Obtain the Refresh Token:
- Use the OAuth 2.0 Playground to obtain the refresh token.
- Click on the gear icon in the top right corner and check "Use your own OAuth credentials."
- Enter your OAuth client ID and client secret created in the previous steps.
- Scroll down and find "Drive API v3" in the list of APIs. Select the scope(s) you need.
- Click the "Authorize APIs" button.
- Follow the steps to authorize the Playground to access your Google Drive.
- Once authorized, exchange the authorization code for tokens.
- The refresh token will be included in the response. Make sure to note it down.
-
Use the Credentials in Your Cloudflare Worker:
- Store the client ID, client secret, and refresh token securely as environment variables or secrets in your Cloudflare Worker.
-
Prerequisites:
- Make sure you have a Cloudflare account. If not, sign up at https://www.cloudflare.com.
-
Create a Cloudflare Worker:
- Log in to your Cloudflare account.
- Go to the "Workers" section from the Cloudflare dashboard.
- Click the "Create a Worker" button.
-
Configure GitHub Repository:
- Fork the repository "Serverless-Temp-File-Sharing" on Yuukio Fuyu Github Page.
- Go to your forked repository.
- Navigate to the
worker.js
file in the repository.
-
Modify the Script:
- Open the
worker.js
file in your forked repository. - Make any necessary configuration changes or adjustments as needed for your deployment.
- Edit this object in the script with the details you generated above.
- Open the
GOOGLE_CLIENT_ID: "",
GOOGLE_CLIENT_SECRET: "",
GOOGLE_REFRESH_TOKEN: "",
DESTINATION_FOLDER_ID: "",
The Destination Folder ID can be found at the back of the Google Drive URL when you open one of your folders. Example:
https://drive.google.com/drive/u/0/folders/
[YOUR_DESTINATION_FOLDER_ID]
-
Deploy to Cloudflare:
- Copy the content of the
worker.js
file in your forked repository.
- Copy the content of the
-
Create a New Cloudflare Worker:
- Go back to your Cloudflare Workers dashboard.
- In the "Script" section, paste the content of the
worker.js
file.
-
Deploy and Test:
- Click the "Save and Deploy" button to deploy the worker.
- Once the deployment is successful, you'll receive a worker URL.
-
Configure Routes:
- To route incoming requests to your Cloudflare Worker, configure the routes.
- Go to the "Routes" section in the Cloudflare Workers dashboard.
- Add a new route (e.g.,
https://your-subdomain.your-domain.com/*
) and associate it with the deployed worker.
-
Testing:
- Access the URL of your worker (e.g.,
https://your-subdomain.your-domain.com/
) to test the deployed script.
- Access the URL of your worker (e.g.,