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
Posts: 64
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Rogers

Phonegap 3.0 File plugin - fileUtils not defined

[ Edited ]

Hello,

 

I'm trying to use the org.apache.cordova.file plugin however there seems to be a problem with the includes. If you look in for example:

 

C:\<myproject>\platforms\blackberry10\www\plugins\org.apache.cordova.file\www\blackberry10\File.js

 

for this code block:

 

/**
 * Returns a "slice" of the file.
 * Slices of slices are supported.
 * start {Number} The index at which to start the slice (inclusive).
 * end {Number} The index at which to end the slice (exclusive).
 */
File.prototype.slice = function(start, end) {
    return fileUtils.createFile(this.nativeFile.slice(start, end));
};

 

fileUtils is not defined. Adding the below line like in FileWriter.js didn't work either:

 

EDIT: actually the below line does work when you use a semi-colon instead of comma! But should still be fixed in the official release too.

 

var fileUtils = require('./BB10Utils');

 

 

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Phonegap 3.0 File plugin - fileUtils not defined

Hi,

 

Thanks for reporting this. I have created an issue in the Apache bug tracker and someone will take a look at it soon.

 

https://issues.apache.org/jira/browse/CB-5015

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Phonegap 3.0 File plugin - fileUtils not defined

We weren't able to reproduce this using the latest version of the plugin.

 

You may want to try re-adding it.

 

cordova plugin rm org.apache.cordova.core.file
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Phonegap 3.0 File plugin - fileUtils not defined

Hi ryansweny, did Bryan's suggestion resolve your issues? If so, could you please mark his reply as the solution? If not, by all means let us know and we'll do our best to help.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Developer
Posts: 64
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Rogers

Re: Phonegap 3.0 File plugin - fileUtils not defined

No, re-adding the plugin never helped. That line of code I mentioned above needed to be added. But really that was just the start of numerous problems with the file, file-transfer and media plugins in cordova 3.0. In the end I wrote native functions myself and added those to an existing plugin I have and that is working now.

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Phonegap 3.0 File plugin - fileUtils not defined

Hi again,

 

I looked into this myself. There was definitely an issue with File.slice. Thank you for the patch! It has been comitted to cordova for the next plugin release:

 

https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-file.git;h=ada89a6

 

You mentioned issues with file-transfer and media as well. If you could report those here or on apache JIRA, it would be greatly appriciated. We are commited to ensuring all of the apache core plugins work well on BB10.

 

Thanks again.

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Developer
Posts: 64
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Rogers

Re: Phonegap 3.0 File plugin - fileUtils not defined

The problems I encountered were in trying to upload a file to an amazon s3 server. The phonegap code we are using works in iOS and Android, but not BlackBerry. If you were to write a demo app that uploaded a photo you would probably encounter many problems as well. Some of them were:

 

1) TEMPORARY file system access is broken and throws an error on intialization ie

 

window.requestFileSystem(LocalFileSystem.TEMPORARY, 5*1024*1024, function(fileSystem){_fileSystem=fileSystem;callback.call(this,_fileSystem);},failure);

 

2) There doesn't seem to be a way to use the file or file transfer api with files saved using a native api. ie how do I upload a photo that is under a dir like /accounts/1000/.../data/ ?

 

3) The file tranfer api puts the actual file part of the HTTP POST call first. It needs to go last.

 

4) Writing a file reports writting 0 bytes and file is not written. Callback does not report useful information like where it tried to save the file.

 

Code:


function writeFile(fileName, data, doAppend, cb) { console.log("In writefile"); getFileSystem(function(fileSystem) { console.log("In requestFileSystem"); console.log("filename: " + fileName); fileSystem.root.getFile(fileName, { create: true, exclusive: false }, function(fileEntry) { console.log("In fileentry"); console.log("In fileentry" + fileEntry.name + " " + fileEntry.fullPath + " " + fileEntry.toURL()); gotFileEntry(fileEntry, data, cb, doAppend, fileEntry.toURL()); }, function(evt) { console.log("Fail gfe"); }); }, function(evt) { console.log("Fail 1"); }); } function gotFileEntry(writer, data, cb, doAppend, fullPath) { console.log("in GFE"); writer.createWriter(function(cw) { gotFileWriter(cw, data, cb, doAppend, fullPath); }, function(evt) { console.log("Fail gfe"); }); } function gotFileWriter(writer, data, cb, doAppend, fullPath) { console.log("in gotFileWriter"); console.log("Writing: " + data); //dubious BB10 hack writer.onwriteend = cb(fullPath); if (doAppend !== undefined && doAppend === true) { writer.seek(writer.length); } writer.write(data); console.log("writer.length: " + writer.length); }


            function getFileSystem(callback,failure){
            if(_fileSystem === undefined || _fileSystem===null){

                //BB10 will not use local filesystem, use discretecamera functions instead for file ops and file transfer
                if (isBB10())
                    window.requestFileSystem(window.PERSISTENT, 5*1024*1024, function(fileSystem){_fileSystem=fileSystem;callback.call(this,_fileSystem);},failure);
                else
                    window.requestFileSystem(window.TEMPORARY, 5*1024*1024, function(fileSystem){_fileSystem=fileSystem;callback.call(this,_fileSystem);},failure);

            }else{
               callback.call(this,_fileSystem);
            }
        }

 

 

5) Can't play a mp3 file. This code throws error with no details:

var my_media = new Media("sounds/test.mp3", success, fail);

 

I have worked around all these problems by writing my own plugins and borrowing snippets from the older webworks plugins, ie using curl for upload, using QFile and QDir for file access etc. In general the older Webworks plugins written in C++ seemed to mostly work whereas the new cordova 3.0.0 plugins implemented using Webkit calls and javascript seem to be mostly broken.

 

Hope this helps,

 

Ryan