nextjs-gcp-storage
nextjs-gcp-storage copied to clipboard
Example Next.js app to upload photos to a GCP storage bucket.
Next.js + GCP Storage Upload
This is an example of a Next.js application allowing you to upload photos to a GCP storage bucket.
Getting Started
Option 1: Use an existing storage bucket.
Retrieve your existing project ID, bucket name, and service account email and private key. Provide those values after clicking "Deploy" to automatically set the environment variables.
Option 2: Create a new bucket.
- Download the Google Cloud SDK so you can use the
gcloud
CLI. - Run
gcloud auth login
. - Inside Google Cloud, create a new project
nextjs-storage-bucket
. - Run
gcloud config set project nextjs-storage-bucket
. - Run
gcloud auth application-default login
, per setup instructions. - Run
pulumi up
to deploy your bucket (it will prompt you to log in). - View your newly created bucket and add the bucket name to
.env.local
(see.env.example
). - Create a new service account with a role of
Storage Object Creator
. - Click "Create Key" and save the JSON file.
- Add the
project_id
,client_email
, andprivate_key
to.env.local
(see.env.example
). - Run
yarn dev
to start the Next app atlocalhost:3000
. - Choose a
.png
or.jpg
file. - You should see your file successfully uploaded to the bucket.
Commands
-
yarn dev
– Starts the Next.js app atlocalhost:3000
. -
pulumi up
– Deploy this stack to GCP.