[TIMOB-1778] Android: Add Method to TiBlob for Retrieving Underlying File
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:57:08.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.5.0 M03 |
Components | Android |
Labels | android, feature |
Reporter | Don Thorp |
Assignee | Bill Dawson |
Created | 2011-04-15T03:02:00.000+0000 |
Updated | 2011-04-17T01:57:08.000+0000 |
Description
See http://developer.appcelerator.com/helpdesk/view/42281">Helpdesk
42281. Add a method to TiBlob.getFile() that returns the
underlying file if it exists. If the TiBlob is not a reference to a
file return null
.
Comments
- Bill Dawson 2011-04-15
From the developer-facing API perspective, the right thing to do here would be to return a FileProxy. However, TiBlob lives in the titanium project (non-module), which to date has no references to our modules.
What do you think is the right way to handle this? Return a TiFile, which lacks API documentation?
- Don Thorp 2011-04-15
Maybe we should just documenting returning a path that can be passed to the filesystem API to get a file object. Would that suffice?
- Bill Dawson 2011-04-15
.nativePath it is.
- Bill Dawson 2011-04-15
Setting back to "new" while not working on it. Still have no idea how to get a file path from a content url, and sick of looking for it for now.
- Bill Dawson 2011-04-15
(from [c5979f87e17694a280d1181d6aafeda399c42d52]) [#1778 state:open] Give TiBlob a nativePath property, but still need it to handle content:// urls in such a way as to be useful to users wnating to create file proxies with it. https://github.com/appcelerator/titanium_mobile/commit/c5979f87e17694a280d1181d6aafeda399c42d52"> https://github.com/appcelerator/titanium_mobile/commit/c5979f87e176...
- Bill Dawson 2011-04-15
(from [36832a4b1976704db3bc1c37120a6950d157039d]) [#1778 state:fixed-in-qa] New .nativePath property will resolve content urls to paths https://github.com/appcelerator/titanium_mobile/commit/36832a4b1976704db3bc1c37120a6950d157039d"> https://github.com/appcelerator/titanium_mobile/commit/36832a4b1976...
- Bill Dawson 2011-04-15
Bear with me while I make a test case - coming soon
- Bill Dawson 2011-04-15
QA: here is an app.js you can use to test this. I'm morphing it into a drillbit test as well, to be committed soon:
Titanium.UI.setBackgroundColor('#000'); var win = Titanium.UI.createWindow({ title:'Test', backgroundColor:'#fff', exitOnClose: true }); win.open() var console = Ti.UI.createLabel({ left:0, right:0, top: 0, height: 400, backgroundColor: 'black', color: 'white', font: {fontSize: 12}, verticalAlign: 'top' }); win.add(console); function w(s){ if (console.text && console.text.length > 0) { console.text = console.text+ '\n\n* ' + s; } else { console.text = '* ' + s; } } var filename = 'blobtest'; var testphrase = 'Revenge of the Blob'; w('getting file with path segments ' + Ti.Filesystem.applicationDataDirectory + ', ' + filename); var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, filename); if (file.exists()) { w('file exists. deleting it.'); file.deleteFile(); } else { w('file did not exist -- no need to delete it.'); } w('putting text "' + testphrase + '" into file'); file.write(testphrase); w('getting blob based on file'); var blob = file.read(); w('destroying original file variable instance to test getting it back via blob'); file = null; var path = blob.nativePath; w("blob says file's path is " + path); w("getting new file instance based on that path"); file = Ti.Filesystem.getFile(path); if (file.exists()) { w("Good - file is said to exist when I get it from that path."); w("Will read contents and see if they match the phrase we put in earlier."); var readphrase = file.read().text; w('Read this text: "' + readphrase + '"'); if (testphrase === readphrase) { w('Yay! The phrases match. TEST SUCCESSFUL'); } else { w('FAIL! The phrases do not match. Something is wrong.'); } } else { w("FAIL - file is said to not exist. Something is wrong."); }
- Bill Dawson 2011-04-15
(from [49374740a28357a89073e187edd5d57a99b0d296]) [#1778][#2553] Unit test for new blob.nativePath property https://github.com/appcelerator/titanium_mobile/commit/49374740a28357a89073e187edd5d57a99b0d296"> https://github.com/appcelerator/titanium_mobile/commit/49374740a283...
- Bill Dawson 2011-04-15
(from [cad3cbee2789d5bb34454a80e85d81bf451f73c4]) [#1778][#2553] Unit test for new blob.nativePath property https://github.com/appcelerator/titanium_mobile/commit/cad3cbee2789d5bb34454a80e85d81bf451f73c4"> https://github.com/appcelerator/titanium_mobile/commit/cad3cbee2789...
- Thomas Huelbert 2011-04-15
G2 2.2 RC2. Bill you rock