arnestone
arnestone

Reputation: 37

Cannot save file with path

I am using the httpModule to call a dropbox rest service to download a text file. When I download it to internal storage it seems happy but then I cannot open the text file with the default app. So now I am pointing the download location to the external storage, but I am getting an error 'Error: Cannot save file with path: /storage/emulated/0/myNewDir'. I have added thee write_external_storage and read_external_storage permissions to the manifest. Here is my code:

HomePage.prototype.getFile = function() {
var filePath = fs.path.join(fs.knownFolders.currentApp().path, "myFile.txt");
storage.createDirectory("myNewDir");

httpModule.getFile({
    url: "https://content.dropboxapi.com/2/files/download",
    method: "POST",
    headers: { "Content-Type": "", 
               "Dropbox-API-Arg": JSON.stringify({"path": "/path/file"}), 
               "Authorization": "*****" },      
}, storage.buildAbsolutePath()+"/myNewDir").then(function (response) {
    console.log(JSON.stringify(response));          
}, function (e) {
    console.log("Error occurred " + e);
});}

Upvotes: 0

Views: 1014

Answers (1)

Peter Staev
Peter Staev

Reputation: 1119

You need to specify the file name in the getFile function, like this:

httpModule.getFile({
    url: "https://content.dropboxapi.com/2/files/download",
    method: "POST",
    headers: { "Content-Type": "", 
               "Dropbox-API-Arg": JSON.stringify({"path": "/path/file"}), 
               "Authorization": "*****" },      
}, storage.buildAbsolutePath()+"/myNewDir/myFile.txt").then(function (response) {
    console.log(JSON.stringify(response));          
}, function (e) {
    console.log("Error occurred " + e);
});}

Upvotes: 1

Related Questions