Foren

way to pass data to callback while file upload using aui

thumbnail
krishna mohan mathakala, geändert vor 7 Jahren.

way to pass data to callback while file upload using aui

Junior Member Beiträge: 68 Beitrittsdatum: 08.09.12 Neueste Beiträge
Hi
is there any way to pass the data from serve resource to call back function(Complete) while uploading file.

When performing a file upload, a subset of global and transaction events will be fired. Specifically, these are:
  • start
  • complete
  • End




Aui file upload uses iframe transport not http transport
Success and Failure events are not processed and fired because the iframe transport does not provide access to the HTTP status and response headers.

How can I pass json data to complete method.

My code looks as below
function uploadFile(event){
            event.preventDefault();
            var myForm = A.one("#<portlet:namespace />myForm");
            var ajaxURL = "<portlet:resourceurl id="UPLOAD_FILE"></portlet:resourceurl>";
            
            var configs = {
                method: 'POST',
                form: {
                    id: myForm,
                    upload: true
                },
                sync: true,
                on: {
                    complete: function(){
                        alert("File Upload Complete!");
                        displayFiles();
                    }
                }
            };
            
            A.io.request(ajaxURL, configs);    
        }
thumbnail
krishna mohan mathakala, geändert vor 7 Jahren.

RE: way to pass data to callback while file upload using aui

Junior Member Beiträge: 68 Beitrittsdatum: 08.09.12 Neueste Beiträge
The following worked for me. its normal ajax file upload


function processFileUpload()
{
var allowFileToUpload = true;

var oMyForm = new FormData();

oMyForm.append("file", document.getElementById("<portlet:namespace />file").files[0]);

$.ajax({
dataType : 'json',
url : url,(Resource url)
data : oMyForm,
type : "POST",
enctype: 'multipart/form-data',
async: false,
processData: false,
contentType:false,
success : function(result) {
},
error : function(result){}
});
return allowFileToUpload;
}