Skip to content

The goal of these two scripts is to demonstrate how to upload files to Google Cloud Storage (GCS) using signed URLs.

Notifications You must be signed in to change notification settings

commitgcp/node-gcs-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GCS Pre-Signed URL Upload Example

This repository contains two JavaScript scripts for uploading files to Google Cloud Storage.

Script 1: generate-urls.js

This script generates a signed URL for uploading a file to Google Cloud Storage using the @google-cloud/storage library. The signed URL is valid for 30 minutes and can be used to upload a image/png file.

Script 2: upload.js

This script uses the fetch and fs libraries to upload a file to a given signed URL. The file is read into memory and uploaded using an HTTP PUT request. The content type header is set to "image/png".

Requirements

Usage

  1. Copy the .env.example file to .env and replace the placeholder values with the actual values relevant to your setup.
  2. Run npm install to install the required libraries
  3. Run npm run generate-urls to generate a signed URL
  4. Copy the signed URL from the console output and add it to the .env file
  5. Run npm run upload to upload a file to the signed URL

Note

  • Please make sure to replace the placeholder values in the scripts with the actual values relevant to your setup.
  • These scripts are for demonstration purposes only. They are not intended for production use.

About

The goal of these two scripts is to demonstrate how to upload files to Google Cloud Storage (GCS) using signed URLs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published