我应该使用哪个 grails 插件来上传大型视频文件,比如 20MB、30MB、100MB,我希望进度条也在那里,我曾尝试为此使用超级文件上传插件,但我认为我做错了什么,它对我不起作用,我应该使用这个,还是其他一些更易于使用的插件,我也看过 Jquery 插件,但因为我一次只需要添加一个视频,我觉得超级文件上传插件对我有好处。
我已经尝试过了,但出现错误,请在下面找到代码。
虽然对于超级文件上传插件的错误:
在我的 GSP 中,我有:
<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>
然后在控制器 saveVideoFile 操作中:
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"
}
}
我在服务中有一个用于保存文件对象的功能:
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
}
}
在保存时,它给出:
方法没有签名:java.io.File.isEmpty() 适用于参数类型:() 值:[] 可能的解决方案:identity(groovy.lang.Closure)、isFile()、list()、dump()、检查()
在线:
if(!tempFile?.isEmpty()){
关于服务功能。
在打印 tempFile 变量时,我正在获取临时存储位置路径。
我知道我做错了什么,任何帮助都会很有用。