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

cloud-storage-resume-signed

v0.2.2

Published

Upload file to a google cloud storage signed URL with resume option

Downloads

27

Readme

Cloud Storage resume signed

Upload manager for google cloud storage signed urls.

The objective of this library its be the most flexible possible, so here its some basics of how resumable uploads works on GCS:

  • By default you can upload a file to a signed URI using the PUT method
  • If you want a resumable upload, you should POST to the signed URI with x-goog-resumable: start header and no body, the response will contain a X-GUploader-UploadID header
  • ALL signed URIs can have a optional query parameter upload_id, its here that you identify a "upload session" and if for some reason lost connection its possible continue from the same byte
  • A upload session have max life of one week
  • You SHOULD use action: 'resumable' instead of write when generating the signed URI

Thats the most basic info you need to use this library, the concept of signed URI and upload id, if you want to know more in details i recommend check the GCS docs.

For this library the difference from a signedURI to a uploadURI its only the upload_id query parameter that you have at the second. You can pass one or another according with you own purpose:

  • If you want permit continue uploads of the same file even in another computer, save the uploadURI at a database and the file hash provided at uploadstarted event. Check latter with the built in cloudStorageSignedResumer.MD5Hash(<file>) function and ask your backend if current user tried to upload a file with the same hash before, to get the same UploadURI and pass as parameter.

  • If you want to continue only at the same browser tab that started the upload give the signedURI only, a built in cache will check for uploads of the same file that have not finished yet.

Example:

<script src="https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/q.js/1.4.0/q.min.js"></script>
<script src="cs-resume-signed.js">
<script>
	document.getElementById('myfileinput').onchange = function(e) {
		let uploader = new cloudStorageSignedResumer.Uploader({
		    'file': this.files[0],
		    'signedURI': '$SIGNED_URI_FROM_BACKEND',
		    'uploadURI': '$UPLOAD_URI'
		})

	      uploader.on('progress', (progress) => {
	          console.log(progress)
	      })
	   
	      uploader.on('uploadstarted', (info) => {
	          console.log(info)
	      })
	     
	      uploader.upload() // starts the upload
	  
	      window.setTimeout(() => {
	          uploader.pause() // pause the upload after 4 seconds
	      }, 4000)
	    
	      window.setTimeout(() => {
	          uploader.upload() // resumes the upload after 10 seconds
	      }, 10000)
	  }
</script>