我正在创建一个应用程序,我想通过进度条将文件上传到Restful服务。我使用REST完成了上传文件,但我不知道如何显示进度条/或上传了多少数据的百分比。
这是控制器的代码:
def uploadDocument() {
if(!params?.documentFile){
render '{"success":false , "message":"Cannot upload an empty file !!!"}'
}
def status = ['success':true,"message":"file_uploaded"]
try{
CommonsMultipartFile file = params.documentFile
def fileLocation ="C:\\Users\\home\\Desktop\\temp_file_upload\\${file.originalFilename}"
file.transferTo(new File( fileLocation))
}catch(Exception e){
status.put("success", false)
status.put("message", "Error_uplodaing the file")
e.printStackTrace(System.out)
}
render status as JSON
}
GSP代码:
<g:uploadForm controller="FileUpload" action="uploadDocument" style="height: 500px;">
<fieldset class="buttons">
<g:submitButton name="upload" class="save" value="Upload" />
</fieldset>
</g:uploadForm>