0

我是新来的Grails框架,我坚持了以下问题:如何Grails的异步上传文件3

  1. 我想与文件上传项目和标题,说明一些细节,我有很大stl 3d文件。虽然文件上传需要时间,我希望用户在下一页上,并填写项目休息的详细信息,如标题说明等。

我无法弄清楚,我将如何做到这一点..我看看grails aynch编程,但我无法弄清楚如何实现。

,如果有人对这个

+0

Grails在这个主题上的指南没有帮助(http://guides.grails.org/grails-upload-file/guide/index.html) – npskirk

+0

感谢npskirk这个链接,但是我正在寻找文件的异步上传 – rupi

+0

这是我如何实现异步hronous: 高清答应= {project.async.task withTransaction {// 长在这里的任务运行 回报 “成功” }} promise.onError {Throwable的错误 - > 的println“发生错误$ {犯错.message}“ } promise.onComplete {result - > println”任务完成$ {result}“ } – rupi

回答

0

我对包括文件上传,这是我想被异步完成一个形式,而回工作指导,我会很感激。它花了很多谷歌搜索,不幸的是我不记得我用过的任何引用,但这是我最终做的。

我在文件输入中包含了一个onchange属性,当选择一个文件时,会调用一个javascript函数来异步验证和上传文件。

文件输入:

<input type="file" name="uploadMedical" id="uploadMedical" onchange="validateAndUpload(this, $(this));" accept=".pdf,.jpg,.jpeg" multiple> 

中的JavaScript (我尽我所能去带出代码是不相关的问题,同时仍留有足够帮助解决你的问题):

function validateAndUpload(input, documentInput){ 
    var uploadForm = $("#uploadForm"); 

    // Stop the browser from submitting the form. 
    uploadForm.submit(function(event) { 
     event.preventDefault(); 
    }); 

    // Get the selected files from the input. 
    var files = input.files; 

    // Create a new FormData object. 
    var formData = new FormData(); 

    // Loop through each of the selected files. 
    for (var ii = 0; ii < files.length; ii++) { 
     var file = files[ii]; 

     // Add the file to the request. 
     formData.append('supportingDocumentation', file, file.name); 
    } 

    //Include ID of record to associate this upload with 
    formData.append('id', getAppealId()); 

    // Submit the form using AJAX. 
    $.ajax({ 
     type: 'POST', 
     dataType : "html", 
     url: url_str, 
     data: formData, 
     processData: false, 
     contentType: false, 
     beforeSend:function(){ 
      //indicate that the file is uploading 
     }, 
     success:function(htmlData){ 
      //display the new list of files on the page 
     }, 
     error:function(ee){ 
      //indicate that the upload failed 
     }, 
     complete:function(){ 
      //reset the file input so more files can be uploaded 
     } 
    }) 
}