0
我使用FileTransfer插件從遠程服務器下載圖像。Phonegap - HTML不顯示存儲器中的圖像
的圖像存儲在「存儲/模擬/ 0 /」 - 使用下面的代碼:
function downloadFile(fileDownloadName){
//console.log('downloadFile');
window.requestFileSystem(
LocalFileSystem.PERSISTENT,
0,
function(fileSystem){
//console.log('onRequestFileSystemSuccess');
fileSystem.root.getFile(
'dummy.html',
{create: true, exclusive: false},
function(fileEntry){
//console.log('onGetFileSuccess!');
var path = fileEntry.toURI().replace('dummy.html', '');
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download(
'https://www.myserver.com/imagens/' + fileDownloadName,
path + fileDownloadName,
function(file) {
//console.log('download complete: ' + file.toURI());
return path + fileDownloadName;
},
function(error) {
console.log('download error source ' + error.source);
console.log('download error target ' + error.target);
console.log('upload error code: ' + error.code);
}
);
},
fail
);
},
fail
);
}
所以,我指着路徑+ fileDownloadName到我的形象的SRC,但圖像不沒出現。
var location = path + fileDownloadName;
window.resolveLocalFileSystemURL(location, function(oFile) {
oFile.file(function(readyFile) {
var reader= new FileReader();
reader.onloadend= function(evt) {
$(".circle-perfil").css('background-image', 'url(' + evt.target.result + ')');
};
reader.readAsDataURL(readyFile);
});
我在做什麼錯?我是否必須將圖像存儲在另一個文件夾中?如果是的話,該怎麼做?
如何指定路徑+ fileDownloadName爲src圖像? plz也分享這條線。 – AAhad 2014-12-05 02:46:17
如果您使用的是img標籤,請嘗試'src'而不是background-image。並確實evt.target.result返回正確的圖像路徑,你有沒有檢查控制檯。 – AAhad 2014-12-05 03:05:57