0

I’m trying to use Tizen download API to download media from a server (images, videos, gifs, etc), and it doesn’t download the file properly. This is the code I used from the tizen docs:

const downloadUrl = 'https://magic-sign.cloud/v4/web/MSlibrary/wi-night-partly-cloudy.jpg';
    const downloadFileName = 'wi-night-partly-cloudy.jpg';
  
    var downloadRequest = new tizen.DownloadRequest(downloadUrl, path, downloadFileName, 'ALL', {'Content-   Type' : 'image/jpeg'});
    
    tizen.systeminfo.getPropertyValue('NETWORK', function(networkInfo) {
        if (networkInfo.networkType === 'NONE') {
            console.log(`Network connection is not available.
                         Download is not possible.`);
            downloadRequest = null;
        }
    });

    var listener = {
        /* When the download progresses (interval is platform-dependent) */
        onprogress: function(id, receivedSize, totalSize) {
            console.log('Received with id: ' + id + ', ' + receivedSize + '/' + totalSize);
        },
    
        /* When the user pauses the download */
        onpaused: function(id) {
            console.log('Paused with id: ' + id);
        },
    
        /* When the user cancels the download */
        oncanceled: function(id) {
            console.log('Canceled with id: ' + id);
        },
    
        /* When the download is completed */
        oncompleted: function(id, fullPath) {
            console.log('Completed with id: ' + id + ', full path: ' + fullPath);
        },
    
        /* When the download fails */
        onfailed: function(id, error) {
            console.log('Failed with id: ' + id + ', error name: ' + error.name);
        }
    };
      
    let downloadId = tizen.download.start(downloadRequest, listener);
  
    tizen.download.getState(downloadId);

    var state = tizen.download.getState(downloadId);

    console.log(state);

    var downloadRequest = tizen.download.getDownloadRequest(downloadId);

    console.log(downloadRequest);

    var MIMEType = tizen.download.getMIMEType(downloadId);
    
    console.log(MIMEType);

and when I try to console.log the download request before the start method this is what I got:

screenshot

and this is the download request and the mime type after the start method, Note: that I explicitely set the the content type to image/jpeg:

screenshot

Also, there is no issue with the download. It keeps saying download complete, and it stores the file in the exact location, but the file is not an image (for this example, I tried to download an image):

screenshot

I’m trying to use Tizen download API to download media from a server (images, videos, gifs, etc), and it doesn’t download the file properly. This is the file output that being stored to the location:

screenshot

Note: when I try to get the image from the same URL using the browser or postman it works fine I got the image with the right size and content type.

Have anyone encountered this problem before?

1 Answers1

0

I wasn't able to reproduce your problems on my setup.

I encourage you to provide more details about how do you performed all steps with complete code. Currently it is hard to determine what could be a problem as you didn't provide code which generates invalid results presented on screenshots.

Here is how I tried to follow your steps:

const downloadUrl = 'https://magic-sign.cloud/v4/web/MSlibrary/wi-night-partly-cloudy.jpg';
const downloadFileName = 'wi-night-partly-cloudy.jpg';
const path = 'downloads';

function printRequest(downloadId, prefix) {
    var state = tizen.download.getState(downloadId);
    var downloadRequest = tizen.download.getDownloadRequest(downloadId);
    try { var MIMEType = tizen.download.getMIMEType(downloadId); } catch (e) { }
    console.log(prefix + " - Request: " + downloadId + ": " + JSON.stringify(downloadRequest) + ", state: " + state + ", mime type: " + MIMEType);
}

var downloadRequest = new tizen.DownloadRequest(downloadUrl, path, downloadFileName, 'ALL', { 'Content-   Type': 'image/jpeg' });

tizen.systeminfo.getPropertyValue('NETWORK', function (networkInfo) {
    if (networkInfo.networkType === 'NONE') {
        console.log(`Network connection is not available.
                         Download is not possible.`);
        downloadRequest = null;
    }
});

var listener = {
    /* When the download progresses (interval is platform-dependent) */
    onprogress: function (id, receivedSize, totalSize) {
        //console.log('Received with id: ' + id + ', ' + receivedSize + '/' + totalSize);
        printRequest(id, "onprogress");
    },

    /* When the user pauses the download */
    onpaused: function (id) {
        console.log('Paused with id: ' + id);
    },

    /* When the user cancels the download */
    oncanceled: function (id) {
        console.log('Canceled with id: ' + id);
    },

    /* When the download is completed */
    oncompleted: function (id, fullPath) {
        printRequest(id, "oncompleted");
        console.log('Completed with id: ' + id + ', full path: ' + fullPath);
    },

    /* When the download fails */
    onfailed: function (id, error) {
        console.log('Failed with id: ' + id + ', error name: ' + error.name);
    }
};

let downloadId = tizen.download.start(downloadRequest, listener);
printRequest(downloadId, "After start");

I've printed download request and mime type before start, after start(synchronously), during download and after download is completed.

After start - Request: 9: {"url":"https://magic-sign.cloud/v4/web/MSlibrary/wi-night-partly-cloudy.jpg","destination":"downloads","fileName":"wi-night-partly-cloudy.jpg","networkType":"ALL","httpHeader":{"Content-   Type":"image/jpeg"},"verifyHost":true}, state: QUEUED, mime type: undefined
onprogress - Request: 9: {"url":"https://magic-sign.cloud/v4/web/MSlibrary/wi-night-partly-cloudy.jpg","destination":"downloads","fileName":"wi-night-partly-cloudy.jpg","networkType":"ALL","httpHeader":{"Content-   Type":"image/jpeg"},"verifyHost":true}, state: DOWNLOADING, mime type: image/jpeg
onprogress - Request: 9: {"url":"https://magic-sign.cloud/v4/web/MSlibrary/wi-night-partly-cloudy.jpg","destination":"downloads","fileName":"wi-night-partly-cloudy.jpg","networkType":"ALL","httpHeader":{"Content-   Type":"image/jpeg"},"verifyHost":true}, state: COMPLETED, mime type: image/jpeg
oncompleted - Request: 9: {"url":"https://magic-sign.cloud/v4/web/MSlibrary/wi-night-partly-cloudy.jpg","destination":"downloads","fileName":"wi-night-partly-cloudy.jpg","networkType":"ALL","httpHeader":{"Content-   Type":"image/jpeg"},"verifyHost":true}, state: COMPLETED, mime type: image/jpeg
Completed with id: 9, full path: /opt/usr/home/owner/content/Downloads/wi-night-partly-cloudy.jpg

It seems that in this way, the mime type is set properly on every step. I also confirmed that the file is valid via sdb shell:

# file --mime-type -b wi-night-partly-cloudy.jpg 
image/jpeg

If my method didn't work for you, please provide more details about which Tizen version do you use, and also what kind of TV device is used in your setup.

15kokos
  • 575
  • 2
  • 8