我目前正在使用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" />
發佈您的代碼.... – Brad 2012-03-15 16:39:54
確定它已完成@Brad。 – Yeppao 2012-03-15 17:07:55