Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write File Support #264

Closed
danbucholtz opened this issue Jul 1, 2016 · 3 comments · Fixed by #283
Closed

Write File Support #264

danbucholtz opened this issue Jul 1, 2016 · 3 comments · Fixed by #283

Comments

@danbucholtz
Copy link

danbucholtz commented Jul 1, 2016

In the File plugin, we should add a method for writing files.

It is kind of painful the way it is now. It was very easy in ngCordova. writeFile(path, file, data, replace)

I wrote this method to do it in a small sample app. It works but we need additional rigor around it.

writeFileInternal(directoryPath, fileName, fileContent){
    return new Promise( (resolve, reject) => {
      (<any>window).resolveLocalFileSystemURL(directoryPath, (fileSystem) => {
        fileSystem.getFile(fileName, {create: true}, (fileEntry) => {
          fileEntry.createWriter( (writer) => {
            writer.onwriteend = function (evt) {
              if (this.error) {
                reject(new Error("Failed to write file"));
              } else {
                resolve(evt);
              }
            };

            writer.write(fileContent);

          }, (err) => {
            console.log("ERROR: ", err);
            reject(err);
          });
        });
      });
    });

Thanks,
Dan

@ihadeed
Copy link
Collaborator

ihadeed commented Jul 1, 2016

Hey @danbucholtz

We have a new wrapper for the File plugin that is here in the dev branch: https://github.com/driftyco/ionic-native/blob/dev/src/plugins/file.ts

I should probably have time next week to finalize the plugin and merge it into master.

@danbucholtz
Copy link
Author

You rock @ihadeed !

@HugoHeneault
Copy link

Any updates about it? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants