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
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T
Accepted Solution

How to write a file using BB 10 HTML5WebWorks

Hi,

 

How to write a file using Blackberry 10 HTML5WebWorks API.

 

https://developer.blackberry.com/html5/api/blackberry.io.file.html#.saveFile

 

The above example is not working in BB 10.

 

Please guide me.

 

 

Thanks,

Shwarup Biswas
Please use plain text.
BlackBerry Development Advisor
bryanhiggins
Posts: 187
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: How to write a file using BB 10 HTML5WebWorks

Hi,

 

You'll need to use the HTML5 file writer. The API you referenced is not supported by BB10.

 

https://developer.blackberry.com/html5/apis/filewriter.html

 

Thanks,

Bryan

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.
Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: How to write a file using BB 10 HTML5WebWorks

If its an image or camera pic taken then this worked for me...

 

Save Pic

 

I struggled to get HTML5 file writer to work - in fact it never did.  Not saying that it won't though.

If it helped you, click like. :smileyhappy:
Please use plain text.
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: How to write a file using BB 10 HTML5WebWorks

Hi Bryan,

 

Any example using "HTML5 file writer" would be appreciated.

 

 

Thanks,

Shwarup Biswas
Please use plain text.
BlackBerry Development Advisor
bryanhiggins
Posts: 187
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: How to write a file using BB 10 HTML5WebWorks

Sure, look at line 95 of this file:

 

https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/invoke/invoker/invocations.js

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: How to write a file using BB 10 HTML5WebWorks

hi Bryan,

 

Thank you so much for your quick reply and sample app.

 

I have a requirement where i need to send a POST request to server and server will return a whole HTML page string as response. I want to save this content in one of my workspace file say "href.html".

 

i implemented bellow code from your sample app :

 

function saveFileInvoke (post, url, data) {
    var xhr = new XMLHttpRequest();
    xhr.open(post, url, false);
    xhr.responseType = 'blob';

    xhr.onload = function(e) {
        blackberry.io.sandbox = false;
        window.webkitRequestFileSystem(PERSISTENT, 1024 * 1024, function(fs) {
            //fs.root.getFile(blackberry.io.sharedFolder + '/downloads/href.html', {create: true}, function(fileEntry) {
             fs.root.getFile('local:///href.html', {create: true}, function(fileEntry) {
                fileEntry.createWriter(function(writer) {

                writer.onerror = function(e) { alert(e) };

                var blob = new Blob([xhr.response], {type: 'text/html'});

                writer.write(blob);

                }, errorHandler);
            }, errorHandler);
        }, errorHandler);
    }

    xhr.send(data);

    blackberry.invoke.invoke({
        //uri: "file:///accounts/1000/shared/downloads/href.html",
        uri: "local:///href.html",
    }, onSuccess, onError);
}

 

but the page is not updating with the new content.

is this two line that i update with my local path is correct?

 

1. fs.root.getFile('local:///href.html', {create: true}, function(fileEntry) {

2. uri: "local:///href.html",

if not what should be path here.

Or am i missing something else.

 

Sorry for this basic question.

 

Thanks,

Shwarup Biswas
Please use plain text.