Cannot save file with path

不问归期 提交于 2019-12-25 05:08:12

问题


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);
});}

回答1:


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);
});}


来源:https://stackoverflow.com/questions/36516648/cannot-save-file-with-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!