Results 1 to 11 of 11
Like Tree1Likes
  • 1 Post By recompile
  1. ignites's Avatar
    CrackBerry Genius

    Posts
    1,670 Posts
    Thread AuthorThread Author   #1  

    Default save/read from file using html5?

    does anyone know how to read or write files in html5? Either or is good I just want to learn it. If someone could give me some barebones code itd be good. Idealy itd be save/read on the pb. I know this forum isnt roamed as much but id like to see if anyone could help me out here. Thanks!
    Developer for easyDial for BlackBerry Bold & inLink for BlackBerry PlayBook
    Find me online via twitter, or on the techfruits.com webpage & twitter account
  2. recompile's Avatar
    CrackBerry Abuser

    Posts
    308 Posts
    #2  

    Default

    The documentation here:

    https://bdsc.webapps.blackberry.com/...ry.io.dir.html

    Should be all you need.
  3. ignites's Avatar
    CrackBerry Genius

    Posts
    1,670 Posts
    Thread AuthorThread Author   #3  

    Default

    honestly ive been over that and I really dont even understand how it is invoked.
    Developer for easyDial for BlackBerry Bold & inLink for BlackBerry PlayBook
    Find me online via twitter, or on the techfruits.com webpage & twitter account
  4. recompile's Avatar
    CrackBerry Abuser

    Posts
    308 Posts
    #4  

    Default

    I don't know what your having trouble with? Here's some code that may help:

    Make sure that you include these in your config.xml file:
    Code:
    <feature id="blackberry.io.file" />
    <feature id="blackberry.utils" />
    Write some data to a file:
    Code:
    <script>
    
      // Where to you want to save the file?
      var filePath = "file:///store/home/user/myfile.txt";
    
      // What do you want to save in the file?	
      var data_to_save = "This string has everything that I want to write to the file";
    
      // Make a blob to write to a file from your string
      var blob_to_write = blackberry.utils.stringToBlob(data_to_save);
    
      // Write the blob to the file 
      blackberry.io.file.saveFile(filePath, blob_to_write);
    
    </script>
    Read from a file:

    Code:
    <script>
    
      // What file do you want to read from? //
      var filePath = "file:///store/home/user/myfile.txt";
    
      // Read data from the file (asynchronous) //
      blackberry.io.file.readFile(filePath, callback_when_read);
    
      // If you want to read the data synchronously instead: //
      // blackberry.io.file.readFile(filePath, callback_when_read, false);
    
      // The following function (specified in your call to readFile) is called
      //  when the file has been read. 
      function callback_when_read(filePath, fileData)
      {
        // Do whatever you want with the file //
    	// filePath = path of file that was read
    	// fileData = a blob containing the contents of the file
    	// (you can name those parameters whatever you want,
    	//  but you need to have both!)
    
    	// You want a string and not a blob?
    	var myData = blackberry.utils.blobToString(fileData);
      }
    
    </script>
    Thanked by 2:
    ignites (04-14-2012),  Superfly_FR (06-29-2012) 
    Superfly_FR likes this.
  5. Justam's Avatar
    CrackBerry Abuser

    Posts
    337 Posts
    PIN
    hrm...
    #5  

    Default

    Quote Originally Posted by recompile View Post
    I don't know what your having trouble with? Here's some code that may help:

    Make sure that you include these in your config.xml file:
    Code:
    <feature id="blackberry.io.file" />
    <feature id="blackberry.utils" />
    Write some data to a file:
    Code:
    <script>
    
      // Where to you want to save the file?
      var filePath = "file:///store/home/user/myfile.txt";
    
      // What do you want to save in the file?	
      var data_to_save = "This string has everything that I want to write to the file";
    
      // Make a blob to write to a file from your string
      var blob_to_write = blackberry.utils.stringToBlob(data_to_save);
    
      // Write the blob to the file 
      blackberry.io.file.saveFile(filePath, blob_to_write);
    
    </script>
    Read from a file:

    Code:
    <script>
    
      // What file do you want to read from? //
      var filePath = "file:///store/home/user/myfile.txt";
    
      // Read data from the file (asynchronous) //
      blackberry.io.file.readFile(filePath, callback_when_read);
    
      // If you want to read the data synchronously instead: //
      // blackberry.io.file.readFile(filePath, callback_when_read, false);
    
      // The following function (specified in your call to readFile) is called
      //  when the file has been read. 
      function callback_when_read(filePath, fileData)
      {
        // Do whatever you want with the file //
    	// filePath = path of file that was read
    	// fileData = a blob containing the contents of the file
    	// (you can name those parameters whatever you want,
    	//  but you need to have both!)
    
    	// You want a string and not a blob?
    	var myData = blackberry.utils.blobToString(fileData);
      }
    
    </script>
    What would one need to save an image from the web to the device? and then would I simply use html<img src="DEVICE FILE PATH"/> to display the image in my webworks app?
  6. ignites's Avatar
    CrackBerry Genius

    Posts
    1,670 Posts
    Thread AuthorThread Author   #6  

    Default

    Quote Originally Posted by recompile View Post
    Write some data to a file:
    Code:
    <script>
    
      // Where to you want to save the file?
      var filePath = "file:///store/home/user/myfile.txt";
    
      // What do you want to save in the file?	
      var data_to_save = "This string has everything that I want to write to the file";
    
      // Make a blob to write to a file from your string
      var blob_to_write = blackberry.utils.stringToBlob(data_to_save);
    
      // Write the blob to the file 
      blackberry.io.file.saveFile(filePath, blob_to_write);
    
    </script>
    this seems to give an error when i m trying to over write or trying to add to a file do you have a solution?
    Developer for easyDial for BlackBerry Bold & inLink for BlackBerry PlayBook
    Find me online via twitter, or on the techfruits.com webpage & twitter account
  7. jeroen_13's Avatar
    CrackBerry Genius

    Posts
    1,541 Posts
    PIN
    Just PM
    #7  

    Default

    Quote Originally Posted by recompile View Post
    I don't know what your having trouble with? Here's some code that may help:

    Make sure that you include these in your config.xml file:
    Code:
    <feature id="blackberry.io.file" />
    <feature id="blackberry.utils" />
    Write some data to a file:
    Code:
    <script>
    
      // Where to you want to save the file?
      var filePath = "file:///store/home/user/myfile.txt";
    
      // What do you want to save in the file?	
      var data_to_save = "This string has everything that I want to write to the file";
    
      // Make a blob to write to a file from your string
      var blob_to_write = blackberry.utils.stringToBlob(data_to_save);
    
      // Write the blob to the file 
      blackberry.io.file.saveFile(filePath, blob_to_write);
    
    </script>
    Read from a file:

    Code:
    <script>
    
      // What file do you want to read from? //
      var filePath = "file:///store/home/user/myfile.txt";
    
      // Read data from the file (asynchronous) //
      blackberry.io.file.readFile(filePath, callback_when_read);
    
      // If you want to read the data synchronously instead: //
      // blackberry.io.file.readFile(filePath, callback_when_read, false);
    
      // The following function (specified in your call to readFile) is called
      //  when the file has been read. 
      function callback_when_read(filePath, fileData)
      {
        // Do whatever you want with the file //
    	// filePath = path of file that was read
    	// fileData = a blob containing the contents of the file
    	// (you can name those parameters whatever you want,
    	//  but you need to have both!)
    
    	// You want a string and not a blob?
    	var myData = blackberry.utils.blobToString(fileData);
      }
    
    </script>


    Which file does it saves ? you only show where it saves it.... how can i change that.. needing this script too
    Developer of; Crackberry Forums Reader app -> Crackberry Forum App (NON-ANDROID)
    Playbook + BB10 DEV , APPS ON REQUEST PLEASE PM ME
    bbUI.js expert -- Need HELP ? Just PM me ! Blackberry Playbook 64GB
    WEBWORKS APP DEVELOPER & APP CONVERTER + SIGNING
  8. recompile's Avatar
    CrackBerry Abuser

    Posts
    308 Posts
    #8  

    Default

    Quote Originally Posted by ignites View Post
    this seems to give an error when i m trying to over write or trying to add to a file do you have a solution?
    What error are you getting? (Use try/catch)

    Is this on phones or tablets? (That makes a difference right now. You'll need an extra tag in your config.xml <rim:permit>access_shared</rim:permit> on tablets. Also, make sure you have the most recent SDK for tablets as the whole file API wasn't implemented in earlier versions and you used to need to use WebKitBlobBuilder to make your blob.)

    Make sure your path is correct. (take a look at blackberry.io.dir.appDirs to help if you're not sure)

    See this for more info:
    https://developer.blackberry.com/htm...y.io.file.html
  9. ignites's Avatar
    CrackBerry Genius

    Posts
    1,670 Posts
    Thread AuthorThread Author   #9  

    Default

    Quote Originally Posted by recompile View Post
    What error are you getting? (Use try/catch)

    Is this on phones or tablets? (That makes a difference right now. You'll need an extra tag in your config.xml <rimermit>access_shared</rimermit> on tablets. Also, make sure you have the most recent SDK for tablets as the whole file API wasn't implemented in earlier versions and you used to need to use WebKitBlobBuilder to make your blob.)

    Make sure your path is correct. (take a look at blackberry.io.dir.appDirs to help if you're not sure)

    See this for more info:
    https://developer.blackberry.com/htm...y.io.file.html
    I forgot what i got when i tried and catch. I dont think this is an access_Share issue because I could save once but not again unless i delete the file. I can read the file too, its just an error if I try to save and the file already exists. I;ll try and get back to you.. but thats odd and no one at rim is responding to me too. I have the latest version of WW.
    Developer for easyDial for BlackBerry Bold & inLink for BlackBerry PlayBook
    Find me online via twitter, or on the techfruits.com webpage & twitter account
  10. recompile's Avatar
    CrackBerry Abuser

    Posts
    308 Posts
    #10  

    Default

    Weird. Well, I tried and couldn't get an error even though I did manage to reproduce the not-overwriting thing (os6). Here's a stupid fix that should work everywhere:

    Code:
    // Before you save ... delete the file //
    if (blackberry.io.file.exists(filePath)) { blackberry.io.file.deleteFile(filePath); }
  11. ignites's Avatar
    CrackBerry Genius

    Posts
    1,670 Posts
    Thread AuthorThread Author   #11  

    Default

    Quote Originally Posted by recompile View Post
    Weird. Well, I tried and couldn't get an error even though I did manage to reproduce the not-overwriting thing (os6). Here's a stupid fix that should work everywhere:

    Code:
    // Before you save ... delete the file //
    if (blackberry.io.file.exists(filePath)) { blackberry.io.file.deleteFile(filePath); }
    O maybe thats why. Im doing this for playbook...
    Developer for easyDial for BlackBerry Bold & inLink for BlackBerry PlayBook
    Find me online via twitter, or on the techfruits.com webpage & twitter account

Posting Permissions