Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
itassets
Posts: 21
Registered: ‎09-09-2011
My Device: developer
My Carrier: developer

BB10 webworks html5 Filewriter

I'd like to create a plain/text file and save id to /documents so the user can exported from the device when connected to the desktop manager. And I can't make filewriter works

 

  function errorHandler(e) {
    var msg = '';
    switch (e.code) {
    case FileError.QUOTA_EXCEEDED_ERR:
      msg = 'QUOTA_EXCEEDED_ERR';
      break;
    case FileError.NOT_FOUND_ERR:
      msg = 'NOT_FOUND_ERR';
      break;
    case FileError.SECURITY_ERR:
      msg = 'SECURITY_ERR';
      break;
    case FileError.INVALID_MODIFICATION_ERR:
      msg = 'INVALID_MODIFICATION_ERR';
      break;
    case FileError.INVALID_STATE_ERR:
      msg = 'INVALID_STATE_ERR';
      break;
    default:
      msg = 'Unknown Error';
      break;
    }
    alert(msg);
  }

  function onInitFs(fs) {
   alert('arranco = ' + blackberry.io.sharedFolder);

    fs.root.getFile( '/documents/exportStock.txt', {create: true}, function(fileEntry) {

    fileEntry.createWriter(function(fileWriter) {

      fileWriter.onwriteend = function(e) {
        //console.log('Write completed.');
        alert('Write completed.');
      };

      fileWriter.onerror = function(e) {
        //console.log('Write failed: ' + e.toString());
        alert('Write failed: ' + e.toString());
      };

      var bb = new BlobBuilder();
      var i;
      var prodActual = new Array(6);
      var hasta = myProductList.length;
      var renglon;
      for (i=0; i<hasta ; i++) {
        prodActual = myProductList[i];
        renglon = '';
        renglon += prodActual[0] + ', ';
        renglon += prodActual[1] + ', ';
        renglon += prodActual[2] + ', ';
        renglon += prodActual[3] + ', ';
        renglon += prodActual[4] + ', ';
        renglon += prodActual[8];

        bb.append(renglon);
      }
      alert('fin append');
      
      fileWriter.write(bb.getBlob('text/plain'));

    }, errorHandler);

  }, errorHandler);

  }
 
 

  function writeFile() {
      blackberry.io.sandbox = false;
      window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
     
    window.requestFileSystem(window.TEMPORARY, 5*1024*1024, onInitFs, errorHandler);
      
  }


    $('#submitExport').live( 'click', function() {
      dataOk = true;
      writeFile();
      
    });
      

 

   alert('arranco = ' + blackberry.io.sharedFolder); shows:

  /accounts/1000/appdata/wmslocator.................../../shared
and the error is NOT_FOUND_ERR';
 
  I have been working with io examples from documentation https://developer.blackberry.com/html5/apis/blackberry.io.html
 
  In my dev alpha when connected to the desktop manager i see the folders books, camera, documents, downloads, misc, music, phots, etc. The folder i'd like to save the file is the documents one.
 
  Any help on what's wrong with the code ?
 
Please use plain text.
Developer
lewellyn
Posts: 110
Registered: ‎10-22-2011
My Device: PlayBook, Bold 9650, Dev Alpha A
My Carrier: Sprint

Re: BB10 webworks html5 Filewriter

Are you requesting the permission to allow you to access the shared folder?

 

In your config.xml, do you have this?

 

<rim:permissions>
    <rim:permit>access_shared</rim:permit>
</rim:permissions>

 



Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Like this post too! :smileyvery-happy:
Please use plain text.
Developer
nunodonato
Posts: 313
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN



your file path must start with blackberry.io.sharedFolder, and then you append the rest "/documents...etc", otherwise you are trying to create a file in the root of the filesystem

 

also, what lewellyn said.

Nuno
theBBthing.wordpress.com - my BlackBerry development blog: news, tips and tutorials
bitoutsidethebox.com - re-imagining digital solutions


Please use plain text.
Contributor
itassets
Posts: 21
Registered: ‎09-09-2011
My Device: developer
My Carrier: developer

Re: BB10 webworks html5 Filewriter

i do have that.
Please use plain text.
Contributor
itassets
Posts: 21
Registered: ‎09-09-2011
My Device: developer
My Carrier: developer

Re: 

adding blackberry.io.sharedFolder throws the same error.
Note i've posted
alert('arranco = ' + blackberry.io.sharedFolder); shows:
/accounts/1000/appdata/wmslocator.................../../shared

also note that the code includes:
blackberry.io.sandbox = false;

Any clue?

and the error is NOT_FOUND_ERR';
Please use plain text.
Contributor
DigitalMaestro
Posts: 38
Registered: ‎03-07-2012
My Device: Dev Alpha B, Playbook 16GB, Z10 LE
My Carrier: Bell Canada

Re: 

I had some issues (different to yours) getting my FileWriter code working as well.  What helped me was determining exactly which function was invoking the errorhandler function.  Create unique versions of errorhandler() (say errorhandler1(), errorhandler2(), etc) and then make sure your code references each error handler only once.  Modify the messages in each so you know which errorhandler() function was called.  Now when the error is thrown you'll know which function caused and this may help with resolution.

 

DM

------------
"The shortest answer is doing." - Jacula Prudentum
My app: Cashalyst
Please use plain text.
Developer
nunodonato
Posts: 313
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: 

Did you fixe this line:

    fs.root.getFile( '/documents/exportStock.txt', {create: true}, function(fileEntry) {

?

 

DigitalMaestro, to find out those sorts of things, you are better off using the inspector and debugging your code. Much simpler and faster,

Nuno
theBBthing.wordpress.com - my BlackBerry development blog: news, tips and tutorials
bitoutsidethebox.com - re-imagining digital solutions


Please use plain text.