Languages

Menu
Sites
Language
FileEntry.toURL not working
FileEntry.toURL delivers a URL that is not usable as source of an image. We are trying to run a web app hosted on a web server within an iFrame of a Tizen-Web-App. The web app downloads an image and stores it in persistent storage using the webkitPersistentStorage and the FileWriter objects. We proved that the image is stored correctly. Using the following code to access the locally stored image var fsUrl = fileEntry.toURL(); document.getElementById('imagePlaceholder').src = fsUrl; we get the following error in the JavaScript console: "Cannot show URL" fsUrl equals to "filesystem:http://{correct ip address}/Persistent/test.jpg". The Tizen-Web-App runs on a Samsung SmartTV running Tizen 2.4. The same code runs in Chrome for Windows or macOS. How can we use the URL returned by fileEntry.toURL to access locally stored images, videos and text files?

Responses

3 Replies
Marco Buettner

I thing you didnt understand the FileSystem-API... The FileSystem-API has no access to online storage, it allows webapps to interact with LOCALE FILES AND FOLDERS ... And also I cant find any "toURL"-Method, only File.toURI();

If u try to link to an image from the internet you need a) internet privileg and b) access to the server on your config.xml ...

Marco Buettner

If I understand something wrong, pls correct me... 

PS: its more helpful to see your current code to find a solution ... my glas ball doesnt work currently correct.

Dirk Mueller

Thank you for your answer, Marco.

Here is the code we use. I have to emphasize, that the problem occurs on a Samsung Tizen 2.4 Display only. The code is used on a website, which is loaded within an iFrame-element of a Tizen-Web-App.

The config.xml of the Tizen-Web-App contains the following line (for test purpose only):

<access origin="*" subdomains="true"/>

We proved that the image is downloaded into local storage, but cannot be accessed using the URL delivered by the FileEntry.toUrl method.

var requestedBytes = 1 * 1024 * 1024 * 1024; // 1 GB
var imageServerUrl = '../iisstart.png';
var imageLocalFilename = 'test.jpg';
var fs;
var blob;

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
function start() {
    navigator.webkitPersistentStorage.requestQuota(requestedBytes, persistentStorageGranted, errorHandler);
}

function persistentStorageGranted(grantedBytes) {
    window.requestFileSystem(window.PERSISTENT, grantedBytes, filesystemAllocated, errorHandler);
}

function filesystemAllocated(obj) {
    fs = obj;
    downloadFile(imageServerUrl, fileDownloaded);
}
        
function fileDownloaded(obj) {
    blob = obj;
    fs.root.getFile(imageLocalFilename, { create: true }, fileCreated, errorHandler);
}

function fileCreated(fileEntry) {
    fileEntry.createWriter(writerCreated, errorHandler);
}
        
function writerCreated(fileWriter) {
    
    fileWriter.onwriteend = function (e) {
        fs.root.getFile(imageLocalFilename, { create: false }, fileRead, errorHandler);
    };

    fileWriter.onerror = errorHandler;

    fileWriter.write(blob);
}

function fileRead(fileEntry) {
    var fsUrl = fileEntry.toURL();
    // ===================================================================================
    document.getElementById('imagePlaceholder').src = fsUrl;
    // Cannot show URL
    // ===================================================================================
}

function downloadFile(url, success) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType = "blob";
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
            if (success) success(xhr.response);
        }
    };
    xhr.send(null);
}

function errorHandler(e) {
    console.log(e);
}