@pozible/signed-upload

Bootstrapped file upload.

Usage no npm install needed!

<script type="module">
  import pozibleSignedUpload from 'https://cdn.skypack.dev/@pozible/signed-upload';
</script>

README

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.