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
Highlighted
New Contributor
Posts: 6
Registered: ‎06-12-2013
My Device: z10, q10
My Carrier: N/A
Accepted Solution

How to copy a pdf file from www folder to shared folder in BB10

How to copy a pdf file from www (html) folder to shared folder in BB10

 

I have tried blackberry.io.file.copy and blackberry.io.filetransfer.download.

None of them works.

 

Can anyone give me a hint.

 

thanks a lot

Retired
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: How to copy a pdf file from www folder to shared folder in BB10

Have a gander at the HTML5 File API and HTML5 FileSystem API (a quick google will find you some amazing how-to's).

 

Once you know how to use the filesystem API, take a look at blackberry.io.  This will show you how to unsandbox your filesystem so that it's the devie's actual filesystem, and not just one within the browser environment using blackberry.io.sandbox = false.

 

Now, to download your pdf from the web, an easy way would be to use a standard xhr request, read the response and create a blob our of it (using the FileAPI) and writing it to the shared folder on the actual filesystem (using blackberry.io.sharedFolder as prefix for your destination path -- note: can't save in the shared folder itself, but you can in any folder than exists within the shared folder).

 

I hope this is a step in the right direction!  If you need any more help or clarification I'll be happy to help Smiley Happy

------------------------------
@grahamzibar
-_- zZZ
New Contributor
Posts: 6
Registered: ‎06-12-2013
My Device: z10, q10
My Carrier: N/A

Re: How to copy a pdf file from www folder to shared folder in BB10

Yes, to download a pdf from server to shared folder work.

 

But what if i have to open a pdf from the aplication package.

the local:///sample.pdf won't work.

I was hoping to copy the local file to the shared folder so that it can be opened from other pdf app.

 

blackberry.io.copy is not avaliable to BB10. so what will be the option to copy the file to shared folder?

 

or is there any way i can get the path or the pdf from my appliation.

 

thanks

Retired
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: How to copy a pdf file from www folder to shared folder in BB10

Use blackberry.io.home to navigate to your app's directory. 

------------------------------
@grahamzibar
-_- zZZ
New Contributor
Posts: 6
Registered: ‎06-12-2013
My Device: z10, q10
My Carrier: N/A

Re: How to copy a pdf file from www folder to shared folder in BB10

I am trying to use blackberry.invoke.card.invokeEmailComposer().

 

to send email with attachments (pdfs) which are embred in the application.

 

so should the attachment file path be  

 var filepath = "file://" + blackberry.io.home+"sample.pdf" 

(assume the sample.pdf is in the root folder of the application)

 

thanks a lot

Retired
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: How to copy a pdf file from www folder to shared folder in BB10

That sounds about right! I can't recall if the blackberry.io.home string contains a trailing '/' character so definitely test to seems if that's there.

 

Lastly, the only issue I can foresee that MIGHT happen is the email functionality might not have access to your app's directory. If that's the case, you'll have to use the filesystem API to copy the file entry from the app's directory to the shared directory. 

 

Hope that makes sense! 

------------------------------
@grahamzibar
-_- zZZ
New Contributor
Posts: 6
Registered: ‎06-12-2013
My Device: z10, q10
My Carrier: N/A

Re: How to copy a pdf file from www folder to shared folder in BB10

yes, i have to copy the file to shared folder.

 

 

the question is how to copy it.

 

here is the code to copy file

window.addEventListener("load", function(e) {
   document.addEventListener("webworksready", function(e) {
        blackberry.io.sandbox = false;
        blackberry.io.file.copy("file://" + blackberry.io.home + '/resources/pdfs/sample.pdf', "file://" + blackberry.io.sharedFolder + "/documents/sample.pdf");
   }
}

 

here is the code from config.xml

    <feature id="blackberry.invoke" required="true" version="1.0.0.0"></feature>
    <feature id="blackberry.invoke.card" required="true" version="1.0.0.0"></feature>
    <feature id="blackberry.io" required="true" version="1.0.0.0"></feature>
    <feature id="blackberry.io.file" required="true" version="1.0.0.0"></feature>
    <feature id="blackberry.io.filetransfer" required="true" version="1.0.0.0"></feature>

    <access uri="file:///" subdomains="true"/>
    <access uri="*" subdomains="true" />>
    
    <rim:permissions>
        <rim:permit>access_shared</rim:permit>
    </rim:permissions>

 

 

However, it is not working, no error too.

please advise. Thanks

Retired
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: How to copy a pdf file from www folder to shared folder in BB10

In BlackBerry 10 there is no blackberry.io.file property since we've adopted the HTML5 FileSystem API.  To accomplish a copy, you would do something like so:

 

blackberry.io.sandbox = false;

window.requestFileSystem(window.TEMPORARY, 1024 x 1024, function success(fs) {

   fs.root.getFile(

      blackberry.io.home + '/whatever.pdf',

      {create: false},

      function success(entry) {

         entry.copyTo(blackberry.io.shared + '/documents',

            null,

            function success() {

               console.log('Ahhhhhh yeahhhhhh');

            },

            function error(e) {  }

         );

      },

      function error(e) {  }

   );

}, function error(e) {  });

 

Boom!  I hope that helps Smiley Happy

------------------------------
@grahamzibar
-_- zZZ
New Contributor
Posts: 6
Registered: ‎06-12-2013
My Device: z10, q10
My Carrier: N/A

Re: How to copy a pdf file from www folder to shared folder in BB10

that make sense, thanks for your help.

 

However, I am getting file error "NOT_FOUND_ERR" from fs.root.getFile().

 

Looks like the blackberry.io.home + '/sample.pdf' is not working somehow.

 

I am sure the sample.pdf is in the same level (root) as the index.html from my application.

 

Retired
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: How to copy a pdf file from www folder to shared folder in BB10

I'll try a quick test and let you know Smiley Happy
------------------------------
@grahamzibar
-_- zZZ