Coder Social home page Coder Social logo

sarbogast / grails-bootstrap-file-upload Goto Github PK

View Code? Open in Web Editor NEW
33.0 8.0 25.0 431 KB

Grails Plugin to integrate Sebastian Tschan's Jquery File Upload

Home Page: http://grails.org/plugin/bootstrap-file-upload

License: Apache License 2.0

Groovy 18.26% Gosu 4.29% CSS 2.89% JavaScript 74.56%

grails-bootstrap-file-upload's Introduction

Description

This plugin integrates the excellent Sebastian Tschan's jquery-file-upload (https://github.com/blueimp/jQuery-File-Upload) into grails 2.0. To view a nice demo of Sebastian's work, click here.

It integrates nicely with Twitter Bootstrap and is completely internationalizable.

Version 1.2.0 of this plugin integrates commit e98f2ae9bfda1dbe2a2e651bec765757237ff104 of jQuery-file-upload

Configuration

This plugin doesn't require any configuration.

Integration

First, add the following line in the header of your page: <r:require modules="bootstrap-file-upload"/>. This will import all of the CSS and Javascript resources needed by this plugin.

Then, add the following tag to your page: <bsfu:fileUpload action="upload" controller="image"/>

Last but not least, if you want to activate the image gallery part, you have to add the following tag, right before the end of your body: <bsfu:imageGallery/>. Thanks to this tag, when you click on an image, it will appear in a modal dialog thanks to which you can navigate through images.

In the bsfu:fileUpload tag, controller and action are the only 2 required attributes. Other attributes include:

  • id: the id of the form (defaults to fileupload)
  • controller: REQUIRED the controller to send files to
  • action: REQUIRED the action to send files to
  • type: The HTTP request method for the file uploads. Can be "POST" or "PUT" (defaults to "POST").
  • dataType: The type of data that is expected back from the server (defaults to 'json')
  • namespace: The namespace used for event handler binding on the dropZone and fileInput collections. If not set, the name of the widget ("fileupload") is used.
  • dropZone: Selector of the element that serves as a drop zone in browsers that support drag and drop (defaults to null)
  • fileInput: Selector of the element that is listened for change events. If undefined, it is set to the file input fields inside of the widget element on plugin initialization.
  • paramName: The parameter name for the file form data (the request argument name). If undefined or empty, the name property of the file input field is used, or "files[]" if the file input name property is also empty. Can be a string or an array of strings.
  • singleFileUploads: By default, each file of a selection is uploaded using an individual request for XHR type uploads. Set this option to false to upload file selections in one request each (defaults to true)
  • limitMultiFileUploads: To limit the number of files uploaded with one XHR request, set the following option to an integer greater than 0. This option is ignored, if singleFileUploads is set to true (defaults to undefined)
  • sequentialUploads: Set this option to true to issue all file upload requests in a sequential order instead of simultaneous requests (defaults to false)
  • limitConcurrentUploads: To limit the number of concurrent uploads, set this option to an integer value greater than 0 (defaults to undefined)
  • forceIframeTransport: Set this option to true to force iframe transport uploads, even if the browser is capable of XHR file uploads. This can be useful for cross-site file uploads, if the Access-Control-Allow-Origin header cannot be set for the server-side upload handler which is required for cross-site XHR file uploads. Defaults to false.
  • redirect: Set this option to the location of a redirect url on the origin server (the server that hosts the file upload form), for cross-domain iframe transport uploads. If set, this value is sent as part of the form data to the upload server. The upload server is supposed to redirect the browser to this url after the upload completes and append the upload information as URL-encoded JSON string to the redirect URL, e.g. by replacing the "%s" character sequence.
  • redirectParamName: The parameter name for the redirect url, sent as part of the form data and set to 'redirect' if this option is empty.
  • postMessage: Set this option to the location of a postMessage window on the upload server, to enable cross-domain postMessage transport uploads. This feature is currently only fully supported by Google Chrome.
  • multipart: By default, XHR file uploads are sent as multipart/form-data. The iframe transport is always using multipart/form-data. If this option is set to false, the file content is streamed to the server url instead of sending a RFC 2388 multipart message for XMLHttpRequest file uploads. Non-multipart uploads are also referred to as HTTP PUT file upload. Additional form data is ignored when the multipart option is set to false. Non-multipart uploads (multipart: false) are broken in Safari 5.1. Defaults to true.
  • maxChunkSize: To upload large files in smaller chunks, set this option to a preferred maximum chunk size. If set to 0, null or undefined, or the browser does not support the required Blob API, files will be uploaded as a whole. For chunked uploads to work in Mozilla Firefox, the multipart option has to be set to false. This is due to Gecko 2.0 (Firefox 4 etc.) adding blobs with an empty filename when building a multipart upload request using the FormData interface - see Bugzilla entry #649150. Several server-side frameworks (including PHP and Django) cannot handle multipart file uploads with empty filenames. If this option is enabled and singleFileUploads is set to false, only the first file of a selection will be uploaded. Defaults to undefined.
  • recalculateProgress: By default, failed (abort or error) file uploads are removed from the global progress calculation. Set this option to false to prevent recalculating the global progress data. Defaults to true.
  • formData: Additional form data to be sent along with the file uploads can be set using this option, which accepts an array of objects with name and value properties, a function returning such an array, a FormData object (for XHR file uploads), or a simple object. The form of the first fileInput is given as parameter to the function. Additional form data is ignored when the multipart option is set to false. Defaults to a function returning the form fields as serialized Array.
  • process: A list of file processing actions. Defaults to [].
  • autoUpload: By default, files added to the UI widget are uploaded as soon as the user clicks on the start buttons. To enable automatic uploads, set this option to true. Defaults to false.
  • maxNumberOfFiles: This option limits the number of files that are allowed to be uploaded using this widget. By default, unlimited file uploads are allowed.
  • maxFileSize: Maximum file size (defaults to 5000000, ie 5MB). This option has only an effect for browsers supporting the File API.
  • minFileSize: The minimum allowed file size, by default 1 byte. The minimum allowed file size, by default 1 byte.
  • acceptFileTypes: regular expression for accepted file type (defaults to /(.|/)(gif|jpe?g|png)$/i)
  • previewSourceFileTypes: The regular expression to define for which files a preview image is shown, matched against the file type. Preview images (before upload) are only displayed for browsers supporting the URL or webkitURL APIs or the readAsDataURL method of the FileReader interface. Default: /^image/(gif|jpeg|png)$/
  • previewMaxSourceFileSize: The maximum file size for preview images in bytes. Defaults to 5000000.
  • previewMaxWidth: The maximum width of the preview images. Defaults to 80.
  • previewMaxHeight: The maximum height of the preview images. Defaults to 80.
  • previewAsCanvas: By default, preview images are displayed as canvas elements if supported by the browser. Set this option to false to always display preview images as img elements. Defaults to true.
  • filesContainer: Selector of the container for the files listed for upload / download. Is transformed into a jQuery object if set as DOM node or string. Defaults to '.files'
  • prependFiles: By default, files are appended to the files container. Set this option to true, to prepend files instead. Defaults to false.
  • uploadTemplateId: The ID of the upload template, given as parameter to the tmpl() method to set the uploadTemplate option. Defaults to 'template-upload'.
  • downloadTemplateId: The ID of the download template, given as parameter to the tmpl() method to set the downloadTemplate option. Defaults to 'template-upload'.
  • loadImages Boolean to indicate whether images should be loaded when the page is first loaded or not. Setting this option to false allows you to control when and how this loading happens. Defaults to true.

Note that starting with version 2.0.0 of the plugin, the list of attributes for the taglib matches jquery file upload options as close as possible. allowDelete and buttonBarClass have been removed. dropZone is now a jQuery selector and params has been renamed as formData.

File handling

Once your page is in place, it is important to understand that the javascript code will GET your controller action once to load existing files, if any, and then it will POST to your controller action once for each file you upload.

Here is an example implementation of the controller:

import org.springframework.http.HttpStatus
import grails.converters.JSON
import org.springframework.web.multipart.MultipartHttpServletRequest
import org.springframework.web.multipart.MultipartFile
import java.awt.image.BufferedImage
import org.imgscalr.Scalr
import javax.imageio.ImageIO

class ImageController {
    def upload() {
        switch(request.method){
            case "GET":
                def results = []
                Image.findAll().each { Image picture ->
                    results << [
                            name: picture.originalFilename,
                            size: picture.fileSize,
                            url: createLink(controller:'image', action:'picture', id: picture.id),
                            thumbnail_url: createLink(controller:'image', action:'thumbnail', id: picture.id),
                            delete_url: createLink(controller:'image', action:'delete', id: picture.id),
                            delete_type: "DELETE"
                    ]
                }
                render results as JSON
                break;
            case "POST":
                def results = []
                if (request instanceof MultipartHttpServletRequest){
                    for(filename in request.getFileNames()){
                        MultipartFile file = request.getFile(filename)

                        String newFilenameBase = UUID.randomUUID().toString()
                        String originalFileExtension = file.originalFilename.substring(file.originalFilename.lastIndexOf("."))
                        String newFilename = newFilenameBase + originalFileExtension
                        String storageDirectory = grailsApplication.config.file.upload.directory?:'/tmp'

                        File newFile = new File("$storageDirectory/$newFilename")
                        file.transferTo(newFile)

                        BufferedImage thumbnail = Scalr.resize(ImageIO.read(newFile), 290);
                        String thumbnailFilename = newFilenameBase + '-thumbnail.png'
                        File thumbnailFile = new File("$storageDirectory/$thumbnailFilename")
                        ImageIO.write(thumbnail, 'png', thumbnailFile)

                        Image picture = new Image(
                                originalFilename: file.originalFilename,
                                thumbnailFilename: thumbnailFilename,
                                newFilename: newFilename,
                                fileSize: file.size
                        ).save()

                        results << [
                                name: picture.originalFilename,
                                size: picture.fileSize,
                                url: createLink(controller:'image', action:'picture', id: picture.id),
                                thumbnail_url: createLink(controller:'image', action:'thumbnail', id: picture.id),
                                delete_url: createLink(controller:'image', action:'delete', id: picture.id),
                                delete_type: "DELETE"
                        ]
                    }
                }

                render results as JSON
                break;
            default: render status: HttpStatus.METHOD_NOT_ALLOWED.value()
        }
    }

    def picture(){
        def pic = Image.get(params.id)
        File picFile = new File("${grailsApplication.config.file.upload.directory?:'/tmp'}/${pic.newFilename}")
        response.contentType = 'image/jpeg'
        response.outputStream << new FileInputStream(picFile)
        response.outputStream.flush()
    }

    def thumbnail(){
        def pic = Image.get(params.id)
        File picFile = new File("${grailsApplication.config.file.upload.directory?:'/tmp'}/${pic.thumbnailFilename}")
        response.contentType = 'image/png'
        response.outputStream << new FileInputStream(picFile)
        response.outputStream.flush()
    }

    def delete(){
        def pic = Image.get(params.id)
        File picFile = new File("${grailsApplication.config.file.upload.directory?:'/tmp'}/${pic.newFilename}")
        picFile.delete()
        File thumbnailFile = new File("${grailsApplication.config.file.upload.directory?:'/tmp'}/${pic.thumbnailFilename}")
        thumbnailFile.delete()
        pic.delete()

        def result = [success: true]
        render result as JSON
    }
}

Browser support

For more information about browser support, see here.

Note that jquery-file-upload supports cross-domain loading but it has been disabled for now in the grails plugin, which shouldn't be a problem.

Customize rendering

Since version 1.1.0, you can now customize how the list of files is rendered by overriding a few templates. Default templates can be found in /views/bootstrapFileUpload directory inside the plugin. Simply copy the relevant template(s) to /view/bootstrapFileUpload in your application to override. If the taglib can find a plugin in your application, it will take precedence over the one in the plugin.

Note that /view/_upload.gsp and /view/_download.gsp are javascript templates. For more information about the syntax of those templates, have a look at the documentation here.

Note: since version 1.1.2, when you add files, they are added to the beginning of the list, not to the end, which is more natural.

Note: since version 2.0.0, you can also customize rendering for the overall form.

grails-bootstrap-file-upload's People

Contributors

aburghelea avatar mclaus avatar sarbogast avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grails-bootstrap-file-upload's Issues

Groovy unable to resolve class org.imgscalr.Scalr

Hi,

I am using Grails version 2.3.3 with Groovy 2.1 and having built the upload controller as per the documentation I get an compilation error as groovy fails to resolve the Scarl class from the import line at teh beginning of the controller file:

import org.imgscalr.Scalr

Consequently all references to the object 'Image' in the controller are unresolved.

Any ideas?

-mike

No such property: r for class: org.grails.plugins.bootstrap.file.upload.BootstrapFileUploadTagLib

I'm getting a no such property error for 'r.script(null)' located in BootstrapFileUploadTagLib.groovy
I can't find any reference to what r.script is for , do you have any idea what the error might be ? am I missing a plugin or running the wrong version of something ?

No such property: r for class: org.grails.plugins.bootstrap.file.upload.BootstrapFileUploadTagLib

Around line 167 of grails-app/taglib/org/grails/plugins/bootstrap/file/upload/BootstrapFileUploadTagLib.groovy

164: out << render(template: "/bootstrapFileUpload/form", plugin: "bootstrap-file-upload", model: model)
165: }
166:
167: out << r.script(null) {
168: out << """
169: $(function(){
170: $('#${id}').fileupload({

Problem with formData attribute

if using the formData attribute with string values the upload does not work anymore, because you get syntax errors in the generated javascript code.

e.g.
formData="[p1:new Date()]"

Fix is to quote the values in line 214 in BootstrapFileUploadTagLib.groovy:

    \$.getJSON(this.action, ${formData ? '{' + formData.collect{k,v->k+':\''+v+'\''}.join(',') + '}' : '{}'}, function (result) {

Chunked File Upload looses some data

I cloned the repo and changed the upload to work with chunks. I set the size to 5mb, for testing I use a 125mb text file (with line numbering) for upload.

After the upload is complete the first lines of the first file look like this:

So there are about 32000 lines missing (exept line 859)

859
32860In vitae tempor est, at varius lectus...
32861
32862Sed sapien sem, eleifend eleifend mollis sit amet, hendrerit vitae sem. Aliquam rhoncus fer

The parts all have 4.8mb in /tmp, except the last one with 466K.

I use grails 2.2.4

Code on my index page:

... maxChunkSize='5000000' />

Upgrade to Bootstrap 2.1.1

Can you please update this app to use the 2.1.1 version of the twitter bootstrap plugin? Would be great if you could update the ApplicationResources to use the proper path of the css and js files, e.g. define your resources like this:

resource url:[plugin: 'bootstrap-file-upload', dir: 'css', file: 'your-resource-here.css']

plugin not working with Grails 2.1.1

does not even compile, due to errors in svn plugin...
(which is required by twitter-bootstrap for whatever strange reasons)

or please let us know that you cannot fix it currently...

thx,
Gernot

File init exception in CleanUploadedFilesJob

There is a error that occurs every time we start our application and do root cause is this line:
def uploadPath = new File(grailsApplication.config.uploadr.defaultUploadPath)

Our workaround is this:

def uploadPath = new File((String)grailsApplication.config.uploadr.defaultUploadPath).

but the problem is that every time plugin is refreshed or rebuilt this error keeps coming up. It would be great if the fix could be included in next release. Thanks.
Best regards,
Luka

2013-05-20 10:50:00,010 ERROR [DefaultPluginScheduler_Worker-9 JobErrorLoggerListener] Exception thrown in job:hungry.wombat.CleanUploadedFilesJob
org.quartz.JobExecutionException: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI) [See nested exception: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI)]
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Caused by: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI)
at hungry.wombat.CleanUploadedFilesJob.execute(CleanUploadedFilesJob.groovy:20)
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:59)
... 2 more
2013-05-20 11:00:00,003 ERROR [DefaultPluginScheduler_Worker-6 JobErrorLoggerListener] Exception thrown in job:hungry.wombat.CleanUploadedFilesJob
org.quartz.JobExecutionException: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI) [See nested exception: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI)]
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Caused by: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI)
at hungry.wombat.CleanUploadedFilesJob.execute(CleanUploadedFilesJob.groovy:20)
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:59)
... 2 more
2013-05-20 11:10:00,004 ERROR [DefaultPluginScheduler_Worker-3 JobErrorLoggerListener] Exception thrown in job:hungry.wombat.CleanUploadedFilesJob
org.quartz.JobExecutionException: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI) [See nested exception: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI)]
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Caused by: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI)
at hungry.wombat.CleanUploadedFilesJob.execute(CleanUploadedFilesJob.groovy:20)
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:59)
... 2 more
2013-05-20 11:20:00,004 ERROR [DefaultPluginScheduler_Worker-10 JobErrorLoggerListener] Exception thrown in job:hungry.wombat.CleanUploadedFilesJob
org.quartz.JobExecutionException: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI) [See nested exception: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI)]
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Caused by: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method () to invoke from this list:
private java.io.File#(java.lang.String, int)
private java.io.File#(java.lang.String, java.io.File)
public java.io.File#(java.lang.String)
public java.io.File#(java.lang.String, java.lang.String)
public java.io.File#(java.io.File, java.lang.String)
public java.io.File#(java.net.URI)
at hungry.wombat.CleanUploadedFilesJob.execute(CleanUploadedFilesJob.groovy:20)
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:59)
... 2 more

Issue when using the plugin in a scaffolded view

Hi,

thanks for the great plugin! I am getting the following stacktrace, when I am calling the tag in a scaffolded view. When I call it in an ordinary view, everything works fine.

I put the following line into /templats/scaffolding/show.gsp

    <bsfu:fileUpload action="upload" controller="image" />

which results in:

| Error 2012-05-12 17:05:29,000 [http-bio-8080-exec-6] ERROR errors.GrailsExceptionResolver  - IllegalArgumentException occurred when processing request: [GET] /backend/product/show/1
Argument [txt] cannot be null or blank. Stacktrace follows:
Message: Error processing GroovyPageView: Error executing tag <bsfu:fileUpload>: Argument [txt] cannot be null or blank
   Line | Method
->> 108 | runTask in /product/show
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by GrailsTagException: Error executing tag <bsfu:fileUpload>: Argument [txt] cannot be null or blank
->>  80 | doCall  in /product/show
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by IllegalArgumentException: Argument [txt] cannot be null or blank
->> 138 | doCall  in org.grails.plugins.bootstrap.file.upload.BootstrapFileUploadTagLib$_closure1$$ENXDLuPg
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   108 | doCall  in product_show$_run_closure2
|   129 | run . . in product_show
|   886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run . . in     ''

Any idea what can cause this issue?

Demo controller does not work with IE

Using IE9 and your controller doesn't work for IE. The POST returns JSON via the Ifram but IE does not know how to render JSON.

Replace the end of the post method line: "render results as JSON" with

            if (request.xhr) {
                render results as JSON
            } else {
                def jsonString = (results as JSON).toString()
                render jsonString
            }

Add to Bootstrap init:

    HttpServletRequest.metaClass.isXhr = {->
        'XMLHttpRequest' == delegate.getHeader('X-Requested-With')
    }

How to do a 'dirty' check on the form if files get uploaded/deleted before the form is saved

Everything works just fine for me, so I'm merely curious as to any ideas how to implement an aspect of the behaviour for my file upload page. It's part of a broader page that also indicates other form parameters via input boxes. I've bound a listener to all 'input's on the form, so that if any change, the user will be prompted before leaving the page that the form has been changed without being saved.

I can't quite figure out how to do the same with the file upload - meaning that if I've uploaded files and they appear in the image gallery, in my case, those files are not committed to my S3 repository until the user saves the form. So if they've uploaded, I want to set the 'dirty' flag on my form to true. But I can't figure out how to intercept that event - the same for when files have been deleted by clicking the "Delete" button for a file.

maxNumberOfFiles writes wrong number

When I specify for example maxNumberOfFiles="5" the Javascript code that will be generated is maxNumberOfFiles: 47.
When I write maxNumberOfFiles="${2-3}" the the Javascript is correct maxNumberOfFiles: 5. When providing a number larger 9 an error is thrown.

Grails 2.2.1

Unresolved Image class in Groovy

Hi,

I am running grails 2.3.3 & groovy 2.1 and have included these additional lines into the BuildConfig:

In dependencies:

    compile 'org.imgscalr:imgscalr-lib:4.2'

And in plugins:

    //PLUGIN FOR MULTIPLE FILE UPLOAD....
    compile ":jquery-ui:1.10.3"
    compile ":twitter-bootstrap:3.1.1"
    compile ":bootstrap-file-upload:2.1.2"

Using the integration part of the installation instructions I have managed to get the file upload interface controls working on a web page with the "bsfu:fileUpload" command.

Then using the 'File Handling' I have cut and pasted the upload and other action/controller code into my controller.

I now have a problem as the controller is failing to compile with an error "Groovy: unable to resolve class Image" - 'Image' being the domain object used in the upload action provided in the configuration documentation.

What step have I missed out - is there another dependency or plugin I should include?

-mike

resources of plugin is not loading

hi, i try to integrate the plugin in 2.0.0 grails application
following your readme instructions with <r:require module="bootstrap-file-upload"/>
and putting the tag on the page
when running i'm getting 404 on the js and css resources of the plugin "Failed to load resource: the server responded with a status of 404 (Not Found)" for the resources reside on the plugin directory

The "+ Add Files..." button require a double-click on IE 10.

The current version of this plugin does not behave correct under IE10. You are forced to double-click on the "Add Files" button to activate the file selection dialog. This should be a single click.

The latest version of blueimp's jQuery-File-Upload claims to have fixed this issue. Can you update to the latest version?

Thanks,
Rob

File not added to table when selecting image in the file explorer

I created a new fresh grails app (2.3.1) to test your plugin.

here's a part of my BuildConfig.groovy :

plugins {
    // plugins for the build system only
    build ":tomcat:7.0.42"

    // plugins for the compile step
    compile ":scaffolding:2.0.1"
    compile ':cache:1.1.1'

    // plugins needed at runtime but not for compilation
    runtime ":hibernate:3.6.10.2" // or ":hibernate4:4.1.11.2"
    runtime ":database-migration:1.3.5"
    runtime ":jquery:1.10.2"
    runtime ":resources:1.2.1"
    // Uncomment these (or add new ones) to enable additional resources capabilities
    //runtime ":zipped-resources:1.0.1"
    //runtime ":cached-resources:1.1"
    //runtime ":yui-minify-resources:0.1.5"

    compile ":jquery-ui:1.10.3"
    compile ":twitter-bootstrap:3.0.2"
    compile ":bootstrap-file-upload:2.1.2"
}

And here's my view page used for the test :

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery File Upload Demo</title>
  <meta name="description" content="File Upload widget with multiple file selection, drag&amp;drop support, progress bar and preview images for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.">
  <meta name="viewport" content="width=device-width">

  <r:require modules="bootstrap-file-upload, bootstrap-image-gallery"/>

  <!-- Shim to make HTML5 elements usable in older Internet Explorer versions -->
  <!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

  <r:layoutResources/>
</head>
<body style="padding-top: 60px;">
<div class="container">
  <div class="page-header">
    <h1>jQuery File Upload Demo</h1>
  </div>
  <bsfu:fileUpload controller="image" action="upload"/>
</div>
<bsfu:imageGallery/>
<r:layoutResources/>
</body>
</html>

I click on the "Add Files", then I select a png file from the file explorer. The selected file is not appended to the table list. Nothing seems to be happened....

Your plugin is really good and I would like to integrate in my app.

Please help me.

Incorrect HTML generated when default codec is html

Thank you for the nice plugin with good documentation.

In the Config.groovy for my app, I have the default codec set to html:

grails.views.default.codec = "html"

This causes all content inside ${ } to be HTML-escaped. It looks like there are a few spots in the plugin's templates that assume that this parameter is set to "none", as the plugin generates the following HTML:

<form id="fileupload" action="/myController/upload" method="POST" enctype=&quot;multipart/form-data&quot;>

and

&lt;!-- The table listing the files available for upload/download --&gt;
&lt;table class=&quot;table table-striped&quot;&gt;
  &lt;tbody class=&amp;quot;files&amp;quot; data-toggle=&quot;modal-gallery&quot; data-target=&quot;#modal-gallery&quot;&gt;

  &lt;/tbody&gt;
&lt;/table&gt;

If I switch the codec to "none" then the HTML gets generated properly, but there are other places in my app that assume this is set to "html".

My proposed solution is to modify the plugin templates to use the <%= %> syntax instead of ${ } when HTML is being produced. So in _list.gsp the following line:

  <tbody ${filesContainer ? (filesContainer.startsWith('.') ? 'class="' + filesContainer.substring(1) + '"' : 'id="' + filesContainer.substring(1) + '"') : 'class="files"'} data-toggle="modal-gallery" data-target="#modal-gallery">

would be replaced with:

<tbody <%=filesContainer ? (filesContainer.startsWith('.') ? 'class="' + filesContainer.substring(1) + '"' : 'id="' + filesContainer.substring(1) + '"') : 'class="files"' %> data-toggle="modal-gallery" data-target="#modal-gallery">

In _form.gsp, replace:

<form id="${id}" action="${url}" method="${type}" ${multipart ? 'enctype="multipart/form-data"' : ''}>

with:

<form id="${id}" action="${url}" method="${type}" <%=multipart ? 'enctype="multipart/form-data"' : ''%> >

and replace:

  ${list}

with:

  <%=list%>

Unresolved Image class

Hi,

I am using Grails version 2.3.3 with Groovy 2.1 and having installed the grails-bootstrap-file-upload
plugin via a compile line in the buildconfig. I have also coded the upload controller/action as per the installation/configuration documentation

I am getting a compilation error when I try to compile the controller - the the object 'Image' being unresolved.

All references to the object 'Image' in the controller are unresolved.

What step have I missed?

-mike

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.