FORGEBOX Enterprise 🚀 - Take your ColdFusion (CFML) Development to Modern Times! Learn More...

UpChunk

v2.0.1 Public

UpChunk

Cookie chunks

All Contributors | Release

Features

  • Chunked uploads 🥧
  • Non-chunked uploads 🍪
  • DropZone support ✅
  • Uploader.js support ✅
  • Easily extendable for other vendors 🔧
  • Supports Adobe 2016, 2018, 2021, and Lucee 5.3.8+ 📒

Getting Started

  1. Install this module into your ColdBox app: box install UpChunk
  2. Configure UpChunk by placing a moduleSettings.UpChunk structure in config/Coldbox.cfc:
moduleSettings = {
    UpChunk : {
      /**
       * Temporary directory used for storing file chunks during upload.
       */
      tempDir : "./tmp/",

      /**
       * Set the final resting place of uploaded files.
       */
      uploadDir : "resources/assets/uploads/"
    }
};
  1. In your ColdBox handler, inject and init your vendor of choice, like [email protected].
  2. Run the handleUpload() method, making sure to pass the current Event object:
function upload( event, rc, prc ){
    var UpChunk = wirebox.getInstance( "[email protected]" );
    var finalFile = UpChunk.handleUpload( arguments.event );

    writeOutput( "Uploaded file to #finalFile#" );
}

Adding an UpChunk Vendor

You can write and use your own custom upload vendor, but it must extend UpChunk.models.AbstractUploader (which also implements UpChunk.models.iChunk.)

component extends="UpChunk.models.AbstractUploader" {

}

Then add a parseUpload() method which takes in the RequestContext object and returns a struct of info about the current upload:

   /**
     * Inspect the current coldbox event
     * and return info about the current upload (if it is an upload.)
     */
    public struct function parseUpload( required struct event ){
        return {
            // is the current request a chunked upload?
            isChunked    : arguments.event.getValue( "dzchunkindex", "" ) != "",
            // what is the upload filename?
            filename     : event.getValue( "file" ),
            // An id unique to each chunked file upload session for tracking and organized groups of chunks.
            uuid         : event.getValue( "dzuuid", "" ),
            // what chunk index is this current request?
            index        : arguments.event.getValue( "dzchunkindex", -1 ),
            // is this the last chunk in the upload
            isFinalChunk : arguments.event.getValue( "dztotalchunkcount", 0 ) == (
                arguments.event.getValue( "dzchunkindex", -1 ) + 1
            )
        };
    }

This will vary depending on the parameters passed in the request. DropZone prepends all chunking parameters with dz, for instance.

Extending UpChunk

For more complex scenarios, you may find it necessary to extend UpChunk.

You can do this by overwriting any or all of the UpChunk methods handleUpload(), handleNormalUpload() or handleChunkedUpload() defined in AbstractUploader.cfc:

/**
 * FunkyUploader
 * Handle abnormal Funky uploads
 */
component extends="UpChunk.models.AbstractUploader" {

   /**
    * FunkyUploads does a funny way of chunking,
    * so we need to massage the chunks a bit to get the upload working right.
    */
   function handleChunkedUpload( required struct upload ){
       // do funky stuff
   }
}

CONTRIBUTING

  • All contributions welcome!
  • Feel free to write a test, fix a README typo, or add a new vendor
  • Take a look at the vendors/DropZone.cfc to get started with a new upload vendor

To get started hacking on UpChunk:

  1. Clone the module - git clone [email protected]:michaelborn/UpChunk.git
  2. Install dependencies - box install
  3. Run tests - cd tests && box testbox run
  4. Write code
  5. Run tests
  6. Push up a pull request

TODO

The Good News

For all have sinned, and come short of the glory of God (Romans 3:23)

But God commendeth his love toward us, in that, while we were yet sinners, Christ died for us. (Romans 5:8)

That if thou shalt confess with thy mouth the Lord Jesus, and shalt believe in thine heart that God hath raised him from the dead, thou shalt be saved. (Romans 10:9)

Repository

Copyright 2021 (and on) - Michael Born

Dependencies (0)


Dev Dependencies (2)


v2.0.1

11 Aug 2021 — 13:23: 38 UTC

🐛 FIX

  • *: Use Github artifacts committer to commit new box.json version (fca7f61)
  • *: Set correct version in box.json (2f0922b)

 

$ box install upchunk

No collaborators yet.
     
  • {{ getFullDate("Aug 11 2021 01:08 PM GMT") }}
  • {{ getFullDate("Aug 11 2021 01:08 PM GMT") }}
  • 119
  • 0
  • 2