Skip to content

Simply bootstrapped file upload to Cloud Storage using Signed URLs

Notifications You must be signed in to change notification settings

pozible/signed-upload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm (scoped) Build Status

@pozible/signed-upload

Use Signed URLs to upload a file straight to Cloud Storage. It returns optimisticUrl to access the file once it is uploaded.

Usage

import signedUpload, { getUrls, upload } from '@pozible/signed-upload'

const {optimisticUrl, signedUrl} = await getUrls(metadata, filePath, config)

await upload(file, metadata, signedUrl)

// Or bootstrap the two commands with
const {optimisticUrl} = await signedUpload(file, metadata, filePath, config)

Arguments

metadata

dimensions attribute is used together with Cloud Function listening on bucket's changes to further process the image. Omit it when uploading generic files.

{
  dimensions: {
    imageUrl: {
      width,
      height
    },
    thumbUrl: {
      ...
    },
    ...
  },
  filename: 'original-filename.ext',
  mimetype: 'valid/type'
}

filePath

A function to provide a final path to the file in your bucket with uuid as a parameter to give random value to the file name. No need to add extension as it will be automatically added based on given filename in metadata.

const filePath = randomId => `/path/to/your/file-with-${randomId}`
const filePath = () => `/path/to/your/original-file-name`

config

  • baseUrl (optional): Add baseUrl to be added to optimisticPath to form complete optimisticUrl.
  • bucketName: When it is deployed to Google Cloud Platform it will use current project, else specify one here.

About

Simply bootstrapped file upload to Cloud Storage using Signed URLs

Resources

Stars

Watchers

Forks

Packages

No packages published