2017 © Pedro Peláez
 

silverstripe-module silverstripe-dropzone

An HTML5 upload field for the CMS and frontend forms.

image

a2nt/silverstripe-dropzone

An HTML5 upload field for the CMS and frontend forms.

  • Tuesday, August 1, 2017
  • by a2nt
  • Repository
  • 0 Watchers
  • 1 Stars
  • 34 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 48 Forks
  • 0 Open issues
  • 17 Versions
  • 21 % Grown

The README.md

Dropzone for SilverStripe

Upload with sanity.

Introduction

The Dropzone module provides FileAttachmentField, a robust HTML5 uploading interfaces for SilverStripe, allowing forms to save file uploads to DataObject instances., (*1)

Features

  • Upload on the frontend, or in the CMS, with one consistent interface
  • Drag-and-drop uploading
  • Automatic client-side thumbnailing
  • Grid view / List view
  • Upload progress
  • Limit file count, file size, file type
  • Permissions for removing/deleting files
  • Tracking files (remove uploaded files that aren't attached to anything)
  • No jQuery dependency

Screenshots

Grid view

, (*2)

List view

, (*3)

Remove/delete files

, (*4)

Beautiful error handling

, (*5)

Any thumbnail size you like

, (*6)

Usage

The field instantiates similarly to UploadField, taking the name of the file relationship and a label, as the first two arguments. Once instantiated, there are many ways to configure the UI., (*7)

FileAttachmentField::create('MyFile', 'Upload a file')
  ->setView('grid')

If the form holding the upload field is bound to a record, (i.e. with loadDataFrom()), the upload field will automatically allow multiple files if the relation is a has_many or many_many. If the form is not bound to a record, you can use setMultiple(true)., (*8)

Image-only uploads can be forced using the imagesOnly() method. If the form is bound to a record, and the relation points to an Image class, this will be automatically set., (*9)

More advanced options

FileAttachmentField::create('MyFiles', 'Upload some  files')
  ->setThumbnailHeight(180)
  ->setThumbnailWidth(180)
  ->setAutoProcessQueue(false) // do not upload files until user clicks an upload button
  ->setMaxFilesize(10) // 10 megabytes. Defaults to PHP's upload_max_filesize ini setting
  ->setAcceptedFiles(array('.pdf','.doc','.docx'))
  ->setPermissions(array(
    'delete' => false,
    'detach' => function () {
      return Member::currentUser() && Member::currentUser()->inGroup('editors');
    }
  ));

Image uploads get a few extra options., (*10)

FileAttachmentField::create('MyImage','Upload an image')
    ->imagesOnly() // If bound to a record, with a relation to 'Image', this isn't necessary.
    ->setMaxResolution(50000000); // Do not accept images over 5 megapixels

Default settings

Default values for most settings can be found in the config.yml file included with the module., (*11)

Usage in the CMS

FileAttachmentField can be used as a replacement for UploadField in the CMS., (*12)

Interacting with the Dropzone interface programatically

For custom integrations, you may want to access the UploadInterface object that manages the upload UI (see file_attachment_field.js). You can do that one of two ways: * If you have jQuery installed, simply access the dropzoneInterface data property of the .dropzone element, (*13)

$('#MyFileDropzone').data('dropzoneInterface').clear();
  • If you are not using jQuery, the UploadInterface object is injected into the browser global window.dropzones, indexed by the id of your .dropzone element.
window.dropzones.MyFileDropzone.clear();

NB: The ID of the actual .dropzone element by default is the name of the form input, with 'Dropzone' appended to it, so FileAttachmentField::create('MyFile') creates a dropzone with an ID of 'MyFileDropzone', (*14)

Tracking / removing unused file uploads

FileAttachmentField::create('MyImage','Upload an image')
    ->setTrackFiles(true)

or:, (*15)

FileAttachmentField:
  track_files: true

To stop users from uploading lots of files and filling the servers hard-drive via the frontend, you can track each file upload in a record, which is then removed when a form saves using Form::saveInto($record)., (*16)

If you do not use Form::saveInto, you will need to manually untrack the file IDs with:, (*17)

FileAttachmentFieldTrack::untrack($data['MyImageID']);

To action the deletion of all the tracked files, you can run the FileAttachmentFieldCleanTask., (*18)

Troubleshooting

Ring Uncle Cheese., (*19)

The Versions

01/08 2017

dev-master

9999999-dev

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

13/10 2016

dev-revert-59-feat-filetracking

dev-revert-59-feat-filetracking

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

28/09 2016

1.4.3

1.4.3.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

21/09 2016

1.4.2

1.4.2.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

20/09 2016

1.4.1

1.4.1.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

20/09 2016

1.4.0

1.4.0.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

08/09 2016

1.3.0

1.3.0.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

05/09 2016

1.2.4

1.2.4.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

31/05 2016

1.2.3

1.2.3.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

18/05 2016

1.2.2

1.2.2.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

24/11 2015

1.2.1

1.2.1.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

18/11 2015

1.2.0

1.2.0.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

06/11 2015

1.1.1

1.1.1.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

28/09 2015

dev-feature/kickassets

dev-feature/kickassets

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

28/09 2015

1.0.1

1.0.1.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

28/09 2015

1.1.0

1.1.0.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader

10/06 2015

1.0

1.0.0.0

An HTML5 upload field for the CMS and frontend forms.

  Sources   Download

BSD-3-Clause

The Requires

 

upload cms files silverstripe forms uploader