This question is locked. New answers and comments are not allowed.
Is there any code sample available on using FileTransfer.Download API. I keep getting "Uncaught ReferenceError: FileTransfer is not defined" in the simulator console window.
Here is the code:
function transferFile(fileSystemPath){
var transfer = new FileTransfer(),
uri = encodeURI("http://icenium.com/assets/img/icenium-logo.png");
filePath = fileSystemPath+'/sample.png';
transfer.download(
uri,
filePath,
function(entry) {
var image = document.getElementById("result");
image.src=entry.fullPath;
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
);
}
Here is the code:
function transferFile(fileSystemPath){
var transfer = new FileTransfer(),
uri = encodeURI("http://icenium.com/assets/img/icenium-logo.png");
filePath = fileSystemPath+'/sample.png';
transfer.download(
uri,
filePath,
function(entry) {
var image = document.getElementById("result");
image.src=entry.fullPath;
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
);
}
10 Answers, 1 is accepted
0
Ashish
Top achievements
Rank 1
answered on 11 Feb 2013, 09:02 PM
Got response on Github. Essentially response is, yes there's sample code on FileTransfer, but they don't work in Simulator.
https://github.com/Icenium/sample-file-transfer/issues/1
https://github.com/Icenium/sample-file-transfer/issues/1
0
divya
Top achievements
Rank 1
answered on 31 Jan 2014, 01:03 PM
hi,
i am working on fileupload to server using phonegap.when i am running in appbuilder simulator "error code=3" error is showing. i searched in google but i am not found any solution.what it means? and how to resolve?
i am working on fileupload to server using phonegap.when i am running in appbuilder simulator "error code=3" error is showing. i searched in google but i am not found any solution.what it means? and how to resolve?
0
Hi divya,
Error 3 is connection error, you can see the errors in the respective Cordova file for the core plugin you're using. We've added support for Cordova FileTransfer plugin in the AppBuilder simulator in the latest version released early this week, so make sure you're up to date.
Also does your app function correctly if deployed on an actual app (not simulator)?
Regards,
Steve
Telerik
Error 3 is connection error, you can see the errors in the respective Cordova file for the core plugin you're using. We've added support for Cordova FileTransfer plugin in the AppBuilder simulator in the latest version released early this week, so make sure you're up to date.
Also does your app function correctly if deployed on an actual app (not simulator)?
Regards,
Steve
Telerik
Icenium is now Telerik AppBuilder, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
0
divya
Top achievements
Rank 1
answered on 03 Feb 2014, 05:40 AM
this is my code, can any body tell me where is the error(error code :3)
(function (global) {
var submitViewModel,
app = global.app = global.app || {};
submitViewModel = kendo.data.ObservableObject.extend({
onsubmit: function () {
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
// Retrieve image file location from specified source
navigator.camera.getPicture(
uploadPhoto,
function(message) { alert('get picture failed'); },
{
quality : 50,
destinationType : navigator.camera.DestinationType.FILE_URI
}
);
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.chunkedMode = false;
alert(options.fileName);
//options.headers = {
// Connection: "close"
// }
var params = new Object();
params.ProfileId = "12345";
params.ProductLeadType = "1";
params.ProductLeadName = "test";
params.ProductLeadDesc = "test desc";
// options.params = params;
// Transfer picture to server
var ft = new FileTransfer();
ft.upload(imageURI, "http://115.119.249.70/tobocwebservices.asmx/SaveImage", win, fail, options,true);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
// console.log("upload error source " + error.source);
// console.log("upload error target " + error.target);
}
}
});
app.submitService = {
viewModel: new submitViewModel()
};
})(window);
(function (global) {
var submitViewModel,
app = global.app = global.app || {};
submitViewModel = kendo.data.ObservableObject.extend({
onsubmit: function () {
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
// Retrieve image file location from specified source
navigator.camera.getPicture(
uploadPhoto,
function(message) { alert('get picture failed'); },
{
quality : 50,
destinationType : navigator.camera.DestinationType.FILE_URI
}
);
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.chunkedMode = false;
alert(options.fileName);
//options.headers = {
// Connection: "close"
// }
var params = new Object();
params.ProfileId = "12345";
params.ProductLeadType = "1";
params.ProductLeadName = "test";
params.ProductLeadDesc = "test desc";
// options.params = params;
// Transfer picture to server
var ft = new FileTransfer();
ft.upload(imageURI, "http://115.119.249.70/tobocwebservices.asmx/SaveImage", win, fail, options,true);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
// console.log("upload error source " + error.source);
// console.log("upload error target " + error.target);
}
}
});
app.submitService = {
viewModel: new submitViewModel()
};
})(window);
0
divya
Top achievements
Rank 1
answered on 03 Feb 2014, 05:45 AM
I tested in device but it showing same error
0
Hello divya,
There is nothing visibly wrong with the code, you can use remote debugging tools like jsHybugger and Weinre to try to pinpoint what is going wrong. You can also setup Fiddler to intercept your device's traffic which would give you a clue what's going on if the problem is failing/wrong requests/responses.
Regards,
Steve
Telerik
There is nothing visibly wrong with the code, you can use remote debugging tools like jsHybugger and Weinre to try to pinpoint what is going wrong. You can also setup Fiddler to intercept your device's traffic which would give you a clue what's going on if the problem is failing/wrong requests/responses.
Regards,
Steve
Telerik
Icenium is now Telerik AppBuilder, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
0
Michael
Top achievements
Rank 1
answered on 04 Feb 2014, 03:49 PM
Divya,
Try these settings:
destinationType: navigator.camera.FILE_URI,
encodingType : navigator.camera.EncodingType.JPEG,
quality: 40,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: 1
and something like this:
uploadPhoto: function (imageURI) {
var options = new FileUploadOptions();
options.chunkedMode = false;
options.headers = {
Connection: "close"
};
// setup parameters
var params = {};
params.fullpath = imageURI;
params.name = options.fileName;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://your-path"), win, fail, options, true);
}
Try these settings:
destinationType: navigator.camera.FILE_URI,
encodingType : navigator.camera.EncodingType.JPEG,
quality: 40,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: 1
and something like this:
uploadPhoto: function (imageURI) {
var options = new FileUploadOptions();
options.chunkedMode = false;
options.headers = {
Connection: "close"
};
// setup parameters
var params = {};
params.fullpath = imageURI;
params.name = options.fileName;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://your-path"), win, fail, options, true);
}
0
Michael
Top achievements
Rank 1
answered on 04 Feb 2014, 04:08 PM
we spent a week on this same problem, and it all came down to that extra "true" parameter on the upload, setting the file dimensions and making sure savetophotoalbum was set.
error code 1 and 3 were never server errors. they were always just fileupload failing and not giving a proper reason why.
error code 1 and 3 were never server errors. they were always just fileupload failing and not giving a proper reason why.
0
divya
Top achievements
Rank 1
answered on 10 Feb 2014, 02:22 PM
I debugged above code,error is rising in cordova.js file and line is
ICE_CordovaExecutionProcessor.Execute(service, action, callbackId, JSON.stringify(args)); here
service:filetransfer
action:upload
callbackId:FileTransfer931564722
how to resolve this?
ICE_CordovaExecutionProcessor.Execute(service, action, callbackId, JSON.stringify(args)); here
service:filetransfer
action:upload
callbackId:FileTransfer931564722
how to resolve this?
0
Marc
Top achievements
Rank 1
answered on 16 Mar 2016, 04:36 PM
Michael your settings changes were the answer for me, I've spent most of the day trying to figure out code 1 and 3 errors. All working now. Thanks