which grails plugin should I use to upload large video files, like 20MB, 30MB, 100MB, I want progress bar also to be there, I have tried to use Super file upload plugin for this, but I think I am doing something wrong in it, it ain't working for me, should I go with this, or some other more easy to use plugin available out there, I have seen Jquery plugin too, but as I only have to add one video in one time, I think super file upload plugin will be good for me.
I have tried it, but getting error, please find below for the code.
Although for the error on the super file upload plugin:
in my GSP I have:
<sfu:generateConfiguration fileSize="300" form="bookForm" buttonWidth="104" buttonHeight="30"/>
<form class="form-horizontal" id="bookForm" name="saveVideoFile" action="saveVideoFile" onsubmit="return sfuSubmitForm(this);">
<div class="control-group">
<label class="control-label" for="inputEmail">Select Category</label>
<div class="controls">
<label class="control-label" for="inputPassword">Upload file</label>
<div class="control-group">
<div class="controls">
Choose file:
<sfu:fileUploadControl></sfu:fileUploadControl>
<br/>
Progress bar: <sfu:fileUploadProgressBar/>
<br/>
</div>
</div>
<input type="submit" value="Save">
</form>
and then in the controller saveVideoFile action:
def saveVideoFile(){
String uploadFilename = params.uploadedFileId
println("params=${params}")
String fileUploaded
if ( uploadFilename ) { // get the full path name of the file from the temp directory
def file = superFileUploadService.getTempUploadFile(uploadFilename)
fileUploaded = fileUploadService.uploadFile( file, "newFile.jpg", "assets/uploadFile/" );
println("fileUploaded=${fileUploaded}")
}else{ // file was not uploaded by flash. User might have javascript off
def fileStream = request.getFile('sfuFile'); // handle normal file upload as per grails docs
fileUploaded = fileUploadService.uploadFile( fileStream, "newFile.jpg", "assets/uploadFile/" );
render "Nothing to upload"
}
}
and I have a function in the service for saving the file object:
String uploadFile( File file, String name, String destinationDirectory ) {
def serveletContext = ServletContextHolder.servletContext
def storagePath = serveletContext.getRealPath( destinationDirectory )
def storagePathDirectory = new File( storagePath )
if( !storagePathDirectory.exists() ){
println("creating directory ${storagePath}")
if(storagePathDirectory.mkdirs()){
println "SUCCESS"
}else{
println "FAILED"
}
}
// Store file
println("file In service=${file}")
//def tempFile = file.getBytes()
def tempFile = file
if(!tempFile?.isEmpty()){
tempFile.transferTo( new File("${storagePath}/${name}") )
println("Saved File: ${storagePath}/${name}")
return "${storagePath}/${name}"
}else{
println "File: ${tempFile.inspect()} was empty"
return null
}
}
On save it is giving:
No signature of method: java.io.File.isEmpty() is applicable for argument types: () values: [] Possible solutions: identity(groovy.lang.Closure), isFile(), list(), dump(), inspect()
at line:
if(!tempFile?.isEmpty()){
on the service function.
and on printing tempFile variable, I am getting temp storage location path.
I know I am doing something wrong, any help will be useful.