Changeset 1508


Ignore:
Timestamp:
Feb 9, 2011, 11:10:38 AM (8 years ago)
Author:
robert@…
Message:
  • Made file upload directory configurable (#282)
  • Fixed bug in uploading multiple files with the same name (#288)

This will only be fully functional after an update of the gdt plugin.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/Config.groovy

    r1469 r1508  
    127127        '/securityinfo/**': ['ROLE_ADMIN']
    128128]
     129
     130// Temporary directory to upload files to.
     131// If the directory is given relative (e.g. 'fileuploads/temp'), it is taken relative to the web-app directory
     132// Otherwise, it should be given as an absolute path (e.g. '/home/user/sequences')
     133// The directory should be writable by the webserver user
     134uploads.uploadDir = "fileuploads"
  • trunk/grails-app/services/dbnp/studycapturing/FileService.groovy

    r1430 r1508  
    1515package dbnp.studycapturing
    1616
     17import java.io.File;
     18
    1719import org.codehaus.groovy.grails.commons.ApplicationHolder
     20import org.codehaus.groovy.grails.commons.ConfigurationHolder
    1821
    1922class FileService implements Serializable {
     
    2932     */
    3033    def File getUploadDir() {
    31         // Find the absolute path to the fileuploads directory. This code is found on
    32         // http://stackoverflow.com/questions/491067/how-to-find-the-physical-path-of-a-gsp-file-in-a-deployed-grails-application
    33         //
    34         // The code used in NMC-DSP didn't work, because that code only works in
    35         // controllers:
    36         //    grailsAttributes.getApplicationContext().getResource("/fileuploads").getFile();
    37         return ApplicationHolder.application.parentContext.getResource("fileuploads").getFile()
     34                // Find the file upload directory name from the configuration
     35                String dir = ConfigurationHolder.config.uploads.uploadDir
     36
     37                if( !dir )
     38                        dir = "fileuploads"
     39
     40                return absolutePath( dir );
    3841    }
     42
     43        /**
     44        * Returns the absolute path for the given pathname. If the pathname is relative, it is taken relative to the web-app directory
     45        * @param pathname
     46        * @return
     47        */
     48   private File absolutePath( String pathname ) {
     49           if( pathname == null)
     50                        return null
     51
     52           // Check if this is an absolute path
     53           File f = new File( pathname );
     54
     55           if( f.isAbsolute() ) {
     56                   return f
     57           } else {
     58                   // Find the absolute path relative to the web-app directory. This code is found on
     59                   // http://stackoverflow.com/questions/491067/how-to-find-the-physical-path-of-a-gsp-file-in-a-deployed-grails-application
     60                   return ApplicationHolder.application.parentContext.getResource(pathname).getFile()
     61           }
     62   }
    3963
    4064    /**
  • trunk/web-app/js/studywizard.js

    r1488 r1508  
    274274                onChange : function(file, ext) {
    275275                        oldFile = $('#' + field_id).val();
    276                         if (oldFile != '') {
     276                        if (oldFile != '' && oldFile != 'existing*' && oldFile != '*deleted*' ) {
    277277                                if (!confirm('The old file is deleted when uploading a new file. Do you want to continue?')) {
    278278                                        return false;
Note: See TracChangeset for help on using the changeset viewer.