2012-03-15 40 views
1

我目前正在使用PhoneGap,然後繼續通過我的應用程序進行FileTransfer上傳。不幸的是,當發送文件時,我沒有通知,也沒有進度條。是否有可能在PhoneGap上收聽FileTransfer Upload的上傳?

我想知道我們是否可以監聽FileTransfer來執行計算進度。 (或者,如果有另一種方式來防止文件傳輸進度的用戶

謝謝

Yeppao

代碼:

var file; 
var pictureSource; // picture source 
var destinationType; // sets the format of returned value 

// Wait for PhoneGap to connect with the device 
// 
document.addEventListener("deviceready",onDeviceReady,false); 

// PhoneGap is ready to be used! 
// 
function onDeviceReady() { 
    pictureSource=navigator.camera.PictureSourceType; 
    destinationType=navigator.camera.DestinationType; 
} 

// Called when a photo is successfully retrieved 
// 
function onPhotoURISuccess(fileURI) { 
    file = fileURI; 

} 


function uploadFile() { 
    alert('up begin'); 
    function uploadSuccess(success) 
    { 
    alert(success); 
    } 

    function uploadError(error) 
    { 
    alert(error); 
    } 

    var options = new FileUploadOptions(); 
    options.fileKey="file"; 
    options.fileName=file.substr(file.lastIndexOf('/')+1); 
    options.mimeType="application/octet-stream"; 

    var params = new Object(); 
    params.title = $("#video-name").val(); 
    params.value2 = "param"; 

    options.params = params; 
    options.chunkedMode = true; 

    var ft = new FileTransfer(); 

    ft.upload(file, "http://myserver/file.php", uploadSuccess, uploadError, options); 

} 

// A button will call this function 
// 
function getFile() { 
    // Retrieve image file location from specified source 
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
     destinationType: destinationType.FILE_URI, 
     sourceType: pictureSource.PHOTOLIBRARY, 
     mediaType: navigator.camera.MediaType.ALLMEDIA }); 
} 

// Called if something bad happens. 
// 
function onFail(message) { 
    alert('Failed because: ' + message); 
} 

這裏的HTML部分:

<div id="file-name"></div> 
    <button style="height: 100px;background-color: #FFF;" data-role="button" onclick="getFile();">From Photo Library</button><br> 
    <input type="text" value="" id="video-name" name="video-name" /> 
<input style="background-color: #FFF;" type="button" id="test" onclick="uploadFile()" name="test" value="Ok" /> 
+0

發佈您的代碼.... – Brad 2012-03-15 16:39:54

+0

確定它已完成@Brad。 – Yeppao 2012-03-15 17:07:55

回答

1

有一個進度條可能會很棘手,但如果你使用jQuery手機,你可以使用$ .mobile.showPageLoadingMsg和$ .mobile.hidePageLoadingMsg

1

我還沒有試過這個,但是,也許你可以從服務器端做到這一點。通過不斷請求一個頁面來向您報告正在上傳的文件的當前更新狀態。

相關問題