npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gcs-browser-resumable-upload

v1.0.3

Published

Send your GCS Session URI to a trusted uploader and let their browser handle the file upload directly to Google API.

Downloads

25

Readme

Google Cloud Storage (GCS) Browser Resumable Upload

Send your GCS Session URI to a trusted uploader and let their browser handle the file upload directly to Google API.

Google do not provide a client side uploader for their own API, but they do provide extensive API docs for their RESTful service.

https://cloud.google.com/storage/docs/performing-resumable-uploads

Single chunk mode has better performance than multiple chunk mode since it uses less requests. The upload is still resumable from the point it failed at, which is checkable using the API.

Basic usage

import { GCSResumableUpload } from 'gcs-browser-resumable-upload';

const fileInput = document.getElementById("fileInput");
const sessionInput = document.getElementById("sessionInput");

const uploader = new GCSResumableUpload(sessionInput.value, fileInput.files[0]);
uploader.onProgress(function(percent) {
    console.log("Progress", percent);
});
uploader.onStateChange(function(newState) {
    console.log("New State", newState);
});
uploader.start();

How it works

The library exports a class GCSResumableUpload. You instantiate it for each resumable upload and provide a GCS resumable URI (AKA Session URI) and a File from an input form element. The upload library does the rest.

Uploads are resumable and retry automatically. No need for checksum storage in local storage since we can check which bytes were persisted even when the connection goes down.

Note: Make sure you initiate the resumable upload with the correct Origin header, or you will run in to CORS errors in the browser.

Bundle this package in to your frontend bundle, or use it as a script module.

Generating a session URI

Generating the Session URI for the resumable upload requires that you are authenticated and have relevant access to the Google Cloud Storage API. This is normally done server side using a service account, and you can use Googles node client libraries for this. Transmission of the session URI should only be over a secure connection and to trusted parties.

import {Storage} from '@google-cloud/storage';

const storage = new Storage();
const bucket = storage.bucket(bucketId);
const file = bucket.file(path);
const response = await file.createResumableUpload({
    origin: myOrigin
});
console.log(response);
// ['https://storage.googleapis.com/upload/storage/xxxxx']