FileTransfer on Blackberry - Error Code 2

387 views
Skip to first unread message

Katrina

unread,
Dec 13, 2011, 11:18:42 AM12/13/11
to phonegap
I am attempting to upload a text file using the sample code.
I am using PG 1.0. Blackberry 6 9800 simulator

fileName = "test.txt";
uploadURL = ip + "/uploadmobile.cfm"; // I tested this and this works
via regular HTML form
//the same ip works properly for AJAX calls


uploadFile(fileName, uploadURL);

function uploadFile(fileName, uploadURL) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=fileName;
options.mimeType="text/plain";


var params = new Object();
params.value1 = "test";
params.value2 = "param";


options.params = params;


var ft = new FileTransfer();
alert("test5");

//FAILS here with error code 2 (security_err) ///the same ip works
properly for AJAX calls

ft.upload(fileName, uploadURL, win, fail, options);
alert("test6");

}

Drew Walters

unread,
Dec 14, 2011, 3:04:50 PM12/14/11
to phon...@googlegroups.com
Where does the "test.txt" file actually exist on the file system? Its
likely failing because the file cannot be found. You should try to
use the file protocol ("file://") and specify the full path to the
file. I've added code to automatically prefix the file protocol if
not specified but its not available in the code you are using.

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Katrina

unread,
Dec 14, 2011, 5:38:34 PM12/14/11
to phonegap
Thank you for your response.

I don't know.
I created the file in a previous step: saveFile(fileName, contents)
(see below)
I'm not sure where that goes.

I have decided to work around the whole thing since I don't really
need a file. I am changing it to an AJAX call that POSTs the data that
would have been in the file.

But if I ever need this...it would be nice to know how to get the full
path to the file that I created.


function saveFile(fileName, contents) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem) {
fileSystem.root.getFile(fileName, {create: true, exclusive: false},
function(fileEntry){

fileEntry.createWriter(function(writer){
writer.onwrite = function(evt) {
alert("write success");
};
writer.write(contents);
} , fail); //createWriter

}, fail); //getFile

}, fail); //requestFileSystem
}

On Dec 14, 3:04 pm, Drew Walters <deedu...@gmail.com> wrote:
> Where does the "test.txt" file actually exist on the file system?  Its
> likely failing because the file cannot be found.  You should try to
> use the file protocol ("file://") and specify the full path to the
> file.  I've added code to automatically prefix the file protocol if
> not specified but its not available in the code you are using.
>

Drew Walters

unread,
Dec 14, 2011, 6:02:56 PM12/14/11
to phon...@googlegroups.com
So, you're specifying the file to be created in the root filesystem
based on this code:

fileSystem.root.getFile(fileName,

So your created file should be at fileSystem.root.fullPath + "/" + fileName

Katrina

unread,
Jan 27, 2012, 6:05:03 PM1/27/12
to phonegap
Hi thanks for the update and sorry it took so long to respond.
That probably was the reason. I switched it to just post to a text
area.

But now I am uploading an image.
I get to the success callback which says Code = 200. The response says
the same as when I do it through a regular PHP file.
When I view the directory listing I see a file with the appropriate
name, but when I click on it it, it goes to my websites 404 handler. I
am guessing the file is somehow corrupted.

I cannot see the file when looking through FTP (so I also cannot
delete these corrupted files).

Here is my code:

tx.executeSql(stmSQL, dataArray, function(tx, results){
alert("sendPhotos: begin for-len="+results.rows.length)
for (var i=0; i<results.rows.length; i++){
var imageURI = results.rows.item(i).file_name;
alert("send photos:"+imageURI)

var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')
+1);
options.mimeType="image/jpeg";

var params = new Object();
params.username = username;
params.staff_id = staff_id;
params.Evaluation_UUID =
results.rows.item(i).Evaluation_UUID;
params.file_name = options.fileName;

options.params = params;
//options.chunkedMode = false;
alert("test before ft")
var ft = new FileTransfer();
ft.upload(imageURI, urlPushPhoto, function(r){
alert("FileTransfer Code = " + r.responseCode);
alert("FileTransfer Response = " + r.response);
alert("Sent = " + r.bytesSent);
}, function(error){
alert("An error has occurred: Code = " + error.code);

}, options);


} //end for
}, errorCB); //tx executeSql

Thank you!

On Dec 14 2011, 6:02 pm, Drew Walters <deedu...@gmail.com> wrote:
> So, you're specifying the file to be created in the root filesystem
> based on this code:
>
> fileSystem.root.getFile(fileName,
>
> So your created file should be at fileSystem.root.fullPath + "/" + fileName
>
Reply all
Reply to author
Forward
0 new messages