Closed j99ht closed 5 years ago
Hi,
If you are using filepicker from iOS then you don't need to search that file under filepicker
directory. You should get direct link. Try console.dir(results)
. Check demo project
This is what I get if I remove filepicker
file:///private/var/mobile/Containers/Data/Application/9F99E06F-C3B0-44D6-B1FA-23A0B8F2528F/tmp/org.nativescript.myapp-Inbox/myfile.hex"
File path /var/mobile/Containers/Data/Application/9F99E06F-C3B0-44D6-B1FA-23A0B8F2528F/Documents/myfile.hex
And file size still 0
hmm.. not sure.. you can search more about UIDocumentPickerViewController
I think the way you are trying to get the size of file is wrong. Did you try to upload file in server after pickup? From Simulator the file is copying to Documents
directory of your APP & from device it's tmp
. So I think the correct way will be:
let folder = knownFolders.documents();
let file = folder.getFile(fileName);
....
Ref: https://docs.nativescript.org/ns-framework-modules/file-system#paths
Yes, I did also in that way and I tried to read it but the file is empty
After download file, was you able to open/read it by using any other APP?
You can have a look here: https://stackoverflow.com/a/48007752/1281864 Try to copy file in some other place after pickup & see how it work.
I currently use this to get the video size:
var defManager = NSFileManager.defaultManager;
var fileAttributes = defManager.attributesOfItemAtPathError(
path
);
var fileSizeNumber = fileAttributes.objectForKey(
NSFileSize
);
var fileSizeNumberB = fileSizeNumber / 1000;
this.size = fileSizeNumberB;
But the path not support, any idea ?
I tried to copy but no success. The file is there but empty.
tested on IOS:
import { File } from "tns-core-modules/file-system";
let results = res.object.get('results'); let path = results[0].file.split('://').pop(); let fileData = File.fromPath(path); console.log(fileData.size);
@paul-castro's solution works. File paths are prefixed with file://
and also URI encoded. You need to remove that part and decode the URI to access files. This is my code to get correct path strings:
paths = paths.map(p => decodeURI(p.replace('file://', '')));
@paul-castro, @erkanarslan thanks for the solution. I wish the File system threw a more straight forward error
When a file is selected and the application tries to read the content, file size is 0
This is my code
file.size is always 0
What I do is to download a file (text file with extension .hex) using Firefox and I want to use that file in my app, reading its content. I find Firefox downloads folder, I select the file, but the file looks empty.
I'm using Nativescript 5.1.0, tns-ios 5.1.1 and "version": "2.0.13" of the plugin