NativeScript / nativescript-background-http

Background Upload plugin for the NativeScript framework
Apache License 2.0
102 stars 50 forks source link

folder location problem ? #88

Closed RoyiNamir closed 6 years ago

RoyiNamir commented 6 years ago

I have an mp3 file which I want to upload.

So this is the hierarchy :

image

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 ?

tsonevn commented 6 years ago

Hi @RoyiNamir, I reviewed your case and found that your case might be related to the path, which you have provided for the file inside the upload method. Regarding that I would suggest moving the raw folder inside te application root folder Edit: and to get the path to the file while using file-system module. With its help, you could access the current app folder path. I am attaching sample project Archive 2.zip

RoyiNamir commented 6 years ago

@tsonevn - why cant i use raw or assets folders like in normal android app? Which is under app resources folder. I just want to know for future developing 🤗

RoyiNamir commented 6 years ago

@tsonevn your demo is not uploadng the mp3 but an image - which is not in the raw folder.

and you access it via documents.path. can you fix it to use the raw folder ? ( becuase it still doesn't find the file)

image

tsonevn commented 6 years ago

HI @RoyiNamir, Excuse me for the inconvenience, I updated my previous comment. I reviewed the plugin implementation and at this time the correct way is to access a file from the project via file-system modules.

RoyiNamir commented 6 years ago

@tsonevn Thanks. so this leaves me only with fs.knownFolders.documents() , right ? Because According to the docs - https://docs.nativescript.org/cookbook/file-system

tsonevn commented 6 years ago

Hi @RoyiNamir , yes, while using the current version of the nativescript-background-http plugin the file path could be accessed with the help of File-System module.

This module allows you to access documents folder, current app folder, and the app Temporary (Caches) folder. More about the methods provided by the file system could be found here.

tsonevn commented 6 years ago

related to https://github.com/NativeScript/NativeScript/issues/5105