2

I am working in cordova 3.4.0 with android. I added FileTransfer plugin for image upload , image get from library and camera working fine but when try to upload its not uploaded give error in Logcat : processMessage failed: Error: ReferenceError: FileTransfer is not defined at file:///android_asset/www/js/cordova.js:1035 I have done all set up in config.xml and AndroidMainfest.xml

config.xml

 <feature name="File">
    <param name="android-package" value="org.apache.cordova.file.FileUtils" />
    <param name="onload" value="true" />
 </feature>
 <feature name="FileTransfer">
    <param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
 </feature>

AndroidMainfest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

cordova_plugins.js

{
    "file": "plugins/org.apache.cordova.file-transfer/www/FileTransfer.js",
    "id": "org.apache.cordova.file-transfer.FileTransfer",
    "clobbers": [
        "window.FileTransfer"
    ]
},

Image upload code

var ft = new FileTransfer();                     
var options = new FileUploadOptions();                      
options.fileKey="vImage1";                      
options.fileName=imagefile.substr(imagefile.lastIndexOf('/')+1);
options.mimeType="image/jpeg"; 
var params = new Object();
params.value1 = "test";
params.value2 = "param";                       
options.params = params;
options.chunkedMode = false;                       
ft.upload(imagefile, serviceURL, win, fail, options); 

So what is wrong in code ? .. Thanks in advance.

Solved:

I have solved this issue . I added following plugins links in html page.

<script type="text/javascript" charset="utf-8" src="plugins/org.apache.cordova.file/www/File.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/org.apache.cordova.file-transfer/www/FileTransfer.js"></script>
Ved
  • 2,701
  • 2
  • 22
  • 30

2 Answers2

0

HI i dont know what you wrong

But this code working fine

var options = new FileUploadOptions();
       options.fileKey = "file";
       options.fileName = uploadimageurl.substr(uploadimageurl.lastIndexOf('/') + 1);


       var params = {};
       params.value1 = "test";
       params.value2 = "param";

       options.params = params;
       var url=unlserviceurl+""+uploadarray.fileurl;
       var ft = new FileTransfer();
       ft.upload(uploadimageurl, encodeURI(url), win, fail, options);

var win = function (r) {
    console.log("Code = " + r.responseCode);
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent);
}

var fail = function (error) {
    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
}

try with this code

Kathir
  • 4,359
  • 3
  • 17
  • 29
  • ok thanks u have any ideas about my question http://stackoverflow.com/questions/22936170/phonegap-android-file-to-base64-out-of-memory-error – Kathir Apr 12 '14 at 06:13
0

To be sure: did you add cordova plugins File and Filtransfer to the project?

user1936277
  • 19
  • 1
  • 7