无法保存路径文件 [英] Cannot save file with path
问题描述
我正在使用httpModule调用保管箱rest服务来下载文本文件.当我将其下载到内部存储时,似乎很高兴,但是随后我无法使用默认应用程序打开文本文件.因此,现在我将下载位置指向外部存储,但是出现错误错误:无法保存路径为/storage/emulated/0/myNewDir的文件".我已经向清单添加了write_external_storage和read_external_storage权限.这是我的代码:
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);
});}
推荐答案
您需要在getFile
函数中指定文件名,如下所示:
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);
});}
这篇关于无法保存路径文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!