Folder location problem?


#1

I’m using nativescript-background-http and I have an mp3 file which I want to upload.

So this is the hierarchy :

And this is how I call it :

 upload1()
    {
        
        var request = {
            url:         "http://localhost:8080/",
            method:      "POST",
            headers:     {
                "Content-Type": "application/octet-stream",
                "File-Name":    "bigpig.jpg"
            },
            description: "{ 'uploading': 'bigpig.jpg' }"
        };
        
        var task = session.uploadFile("/raw/a1.mp3", request);
     
    }

But I get an error :

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

Question:

Should my mp3 file ( beep sound) be at raw at first place ? and if so - how can I use session.uploadFile(..) with the right path ?


#2

Did you try res://a1 @Royi_Namir

Edit: removed file extension
@sean-perkins is right


#3

@multishiv19

  • Does res:// referes to raw ??? I don’t understand. the file is an mp3. not image.
  • ( and what about assets folder ?)
  • where an mp3 should be at first place ? this is a sound for the app,

#4

As mentioned by @multishiv19 anything inside App_Resources needs to be referenced from res://. For instance: res://raw/a1. You typically do not need to specify the extension, at least I’ve found that for images.


Nativescript and resources folder - is there a simple solution?
#5

@sean-perkins well - there is a problem :

I’m trying to upload a file : (via nativescript-background-http)

File url : this.fileURL = "res://raw/a1"; //i’ve also tried a1.mp3

Uploading…

With this code :

  var request = {
            url:         "http://posttestserver.com/post.php",
            method:      "POST",
            headers:     {
                "Content-Type": "application/octet-stream",
                "File-Name":    "bigpig.jpg"
            },
            description: "{ 'uploading': 'bigpig.jpg' }"
        };
        
        var task = session.uploadFile( this.fileURL, request);

But then I see

JS: ERROR Error: java.io.FileNotFoundException: Could not find file at path: res://raw/a1
JS: net.gotev.uploadservice.UploadFile.(UploadFile.java:39)
JS: net.gotev.uploadservice.BinaryUploadRequest.setFileToUpload(BinaryUploadRequest.java:60)


#6

You could try manually finding the file through the file-system package.

For downloading files, I know I had to reference the file location like file://path_to_file.


#7

@sean-perkins So now I’m confused.
When should I use knownFolders.documents().path+...myffile VS file://...myffile ? please(!) put some clarification in my mind :slight_smile:


#8

file:// behaves the same as if you were to put file:// in your browser and press enter. It’s a shortcut accessor to the base-level file-system path. Now I don’t know if knownFolders.documents() is the same as file or not. I would assume documents is a level deeper.

Your error is 100% tied to not finding the file, so if you figure which path is valid, you’ll be moving forward.