[TIMOB-7713] Parity: Android does not write downloaded file to directory while iOS writes it to the directory
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2017-07-26T23:46:08.000+0000 |
Affected Version/s | Release 1.8.2 |
Fix Version/s | n/a |
Components | TiAPI |
Labels | api, parity |
Reporter | Natalie Huynh |
Assignee | Eric Merriman |
Created | 2012-02-17T15:21:08.000+0000 |
Updated | 2017-07-26T23:46:08.000+0000 |
Description
Steps to Reproduce:
1. Run the following code:
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
win1.open();
/*
* TEST 1.8.X DOWNLOADING THE SAME FILE MULTIPLE TIMES
*
* NOTE: Will need to create: Titanium.Filesystem.applicationDataDirectory + "/projects/" + p[1-5] to write into
*/
for (var i=1; i<=5; i++) {
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "projects", "p"+i);
if (!file.exists()) {
file.createDirectory(true);
}
}
function jsleep(s){
s=s*1000;
var a=true;
var n=new Date();
var w;
var sMS=n.getTime();
while(a){
w=new Date();
wMS=w.getTime();
if(wMS-sMS>s) a=false;
}
}
var button1 = Titanium.UI.createButton({
top:'10',
title:'Test Downloading Same File 5 Times (1.8.X)',
width:'400',
height:'40'
});
button1.addEventListener('click', function()
{
downloadafile("p1", "g.jpg", "http://www.gonzoville.com/wp-content/uploads/2011/12/0.jpeg");
jsleep(1);
downloadafile("p2", "g.jpg", "http://www.gonzoville.com/wp-content/uploads/2011/12/0.jpeg");
//jsleep(1);
downloadafile("p3", "g.jpg", "http://www.gonzoville.com/wp-content/uploads/2011/12/0.jpeg");
//jsleep(1);
downloadafile("p4", "g.jpg", "http://www.gonzoville.com/wp-content/uploads/2011/12/0.jpeg");
//jsleep(1);
downloadafile("p5", "g.jpg", "http://www.gonzoville.com/wp-content/uploads/2011/12/0.jpeg");
});
win1.add(button1);
Ti.API.info("BASE PATH: " + Titanium.Filesystem.applicationDataDirectory);
/* NOW LETS MAKE IT WORK WITH 1.8.1 ... NOT! */
function downloadafile(foldername, filename, fileurl) {
//var file = Ti.Filesystem.pathFromComponents(Ti.Filesystem.applicationDataDirectory, "projects", foldername, filename);
var c = Titanium.Network.createHTTPClient({
timeout : 10000,
onload : function(e) {
Ti.API.info('LOADED ' + filename + " TO " + foldername);
Ti.API.info(c.status);
},
ondatastream : function(e) {
Ti.API.info('ONDATASTREAM - PROGRESS: ' + e.progress);
},
onerror : function(e) {
Ti.API.info('XHR Error ' + e.error);
}
});
c.clearCookies("all");
c.open('GET', fileurl);
c.file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory + "/projects/" + foldername + "/" + filename);
c.send();
}
Actual:
The downloaded files are saved on iOS, but not on Android
Expected:
For files to be saved to Android
Closing due to inactivity. If this issue still exists, please raise a new ticket.