Create a Directory in PhoneGap Application

后端 未结 2 754
梦如初夏
梦如初夏 2020-12-08 11:22

Trying to figure out how to create a directory on the file system using PhoneGap.

I want to create a directory for my PhoneGap application, so I can store images the

2条回答
  •  轮回少年
    2020-12-08 11:43

    This code works for me (based on version 7 Cordova documentation - https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/index.html):

    window.resolveLocalFileSystemURL('cdvfile://localhost/persistent/',
      function fileEntryCallback(fileEntry) {
        fileEntry.getDirectory('my_directory', { create: true });
      }
    );
    

    If the code above doesn't work, you may need to reinstall the File and File Transfer plugins. A command like console.log(window.resolveLocalFileSystemUrl) is one way to test that the plugins are working.

    Also, if you're using Content Security Policy (CSP) be sure your default-src allows cdvfile: paths:

    default-src cdvfile:

提交回复
热议问题