Nativescript and resources folder - is there a simple solution?


#1

I will start with the fact that currently I’m uploading successfully
an mp3 file to a server - but via a hacky way.

I’m having 2 raw folders as you can see :

enter image description here

And here is the working code to upload the file :

 upload1()
    {
        
        let file = fs.path.join(fs.knownFolders.currentApp().path, "raw/a1.mp3");
        
        var request = {
            url:         "http://posttestserver.com/post.php",
            method:      "POST",
            ...
        };
        
        var task = session.uploadFile(file, request);
        task.on("progress", this.logEvent);
        
    }

Here is the output for the successful upload (showing progress)

So where is the problem ?

The current file is being uploaded from the root raw folder. (proof)

But the right way (as I was told)is to upload it via the raw folder or the assets folder and then reference it via res://raw/a1.mp3 ( or res://raw/a1).

So I’ve switched to : let file="res://raw/a1.mp3";

But got an error:

ERROR Error: java.io.FileNotFoundException: Could not find file at
path: res://raw/a1.mp3

Also for : let file="res://raw/a1"; //without extension - Got an error :

JS: ERROR Error: java.io.FileNotFoundException: Could not find file at
path: res://raw/a1

Question:
How can I access the mp3 file under the raw folder? (not the outside folder but the resource one)