How to transfer a captured image using the ngcordova file transfer plugin to my ftp

I am trying to upload an image to my FTP.

what i have achieved so far is in this plnkr

My transfer of cordova file looks like

$scope.upload =function(){ var options = { fileKey: "file", fileName: "gopi", chunkedMode: false, mimeType: "image/jpeg", params : {'user_token':' Chandru@123 ', 'user_email':'wepopusers'} // directory represents remote directory, fileName represents final remote file name }; console.log(options); $cordovaFileTransfer.upload('ftp://308.3d8.myftpupload.com/', MyService.getImgPath(), options) .then(function(result) { // Success! console.log(result); console.log("SUCCESS: " + JSON.stringify(result.response)); alert('ftp success'); }, function(err) { // Error console.log(err); alert('ftp fail'); console.log("ERROR: " + JSON.stringify(err)); }, function (progress) { // constant progress updates console.log(progress); }); }; 

My answer to my error function for cordova file looks like

FileTransferError {code: 2, source: "file: ///storage/sdcard0/Android/data/com.ionicframework.camera108827/cache/1462186990291.jpg", target: " ftp://308.3d8.myftpupload.com/ " , http_status: null, body: null ...} body: nullcode: 2exception: nullhttp_status: nullsource: "file: /// storage / sdcard0 / Android / data / com. ionicframework.camera108827 / cache / 1462186990291.jpg" target: " ftp://308.3d8.myftpupload.com/ " proto : object

I have a TakePicture button that will display a pic and show to the user, and also I have a function to load using cordovafiletransfer $ scope.upload .

My ftp host ftp://308.3d8.myftpupload.com/ username and password are in my encoding. I have the name of the gopi folder where my image should be stored.

my path to the selected image is in the imageURI parameter, so I used services to set the path.

I'm confused steps

1) I cannot understand the var options object in the cordova file transfer plugin.

2) I do not get any erro when remote debugging, but I only raise my funtion error in my cordova file transfer.

How to update captured image on FTP using IONIC

UPDATE

Thanks gandhi, answer https://github.com/xfally/cordova-plugin-ftp how I managed to connect to ftp without multipart.

but in this

$ window.cordova.plugin.ftp.upload ("/ ping", "/ gopi / ping", function (percent) {

I do not know what to do in the first argument and in the second.

$ window.cordova.plugin.ftp.upload ("/default.prop", "/gopi/default.prop", function (%) {

The above line success is completely sent to my ftp, but I cannot post my image, which is stored in my ping variable.

https://plnkr.co/edit/ETGmdl4B0d5dlHWdJQ9m?p=info

+5
source share
1 answer

The answer to your first question is available in the official file transfer plugin documentation. The following excerpt

 options: Optional parameters (Object). Valid keys: fileKey: The name of the form element. Defaults to file. (DOMString) fileName: The file name to use when saving the file on the server. Defaults to image.jpg. (DOMString) httpMethod: The HTTP method to use - either PUT or POST. Defaults to POST. (DOMString) mimeType: The mime type of the data to upload. Defaults to image/jpeg. (DOMString) params: A set of optional key/value pairs to pass in the HTTP request. (Object, key/value - DOMString) chunkedMode: Whether to upload the data in chunked streaming mode. Defaults to true. (Boolean) headers: A map of header name/header values. Use an array to specify more than one value. On iOS, FireOS, and Android, if a header named Content-Type is present, multipart form data will NOT be used. (Object) 

Pay attention to for more information.

For your second question, try getting the error code in the error callback function and try to narrow down the problem.

Update: I think ftp download is not possible with the file transfer plugin. The plugin definition itself states "The FileTransfer object provides a way to upload files using an HTTP multi-part POST or PUT request, and to download files"

You may need to look at the ftp client to download ftp.

+1
source

All Articles