如何使用ngcordova文件传输插件传输拍摄的图像到我的FTP [英] how to transfer the taken image using ngcordova file transfer plugin to my ftp

查看:663
本文介绍了如何使用ngcordova文件传输插件传输拍摄的图像到我的FTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图片上传到我的FTP。



到目前为止,我在此 plnkr



我的cordova文件传输看起来像

  $ scope。 upload = function(){

var options = {
fileKey:file,
fileName:gopi,
chunkedMode:false,
mimeType:image / jpeg,
params:{'user_token':'Chandru @ 123','user_email':'wepopusers'} //目录代表远程目录,fileName代表最终远程文件名
};
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');
$ b console.log(err);
console('ftp fail');
console.log(ERROR: + JSON.stringify(err));
},function(progress){
//常量进度更新
console.log(progress);
}

};

我对cordova文件的错误函数的回复看起来像


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.jpgtarget: ftp://308.3d8.myftpupload.com/ proto :对象


我有按钮 TakePicture ,它会拍摄照片并显示给用户,我还有一个功能使用cordovafiletransfer上传 $ scope.upload strong>。



我的ftp主机是 ftp://308.3d8.myftpupload.com/ 用户名和密码是给我在我的编码在这我有一个文件夹名称 gopi ,我的图像应该存储。



我的路径的图像拍摄是在imageURI









1)我无法理解cordova文件传输插件中的 var options 对象。



2)我没有得到任何错误,而远程调试,但我只是调用我的错误功能在我的cordova文件传输。



如何更新我拍摄的图像到FTP IONIC


UPDATE



感谢gandhi回答 https://github.com/xfally/cordova-plugin-ftp 一些如何




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


我不知道在第一个参数和第二个。


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


以上行成功完全张贴到我的FTP,但我不能张贴我的图像存储在我的ping变量。



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

解决方案

您的第一个问题的答案可以在官方文件传输插件,摘录如下,

 选项:可选参数(Object)有效键:

fileKey:表单元素的名称默认为文件(DOMString)
fileName:在服务器上保存文件时使用的文件名,默认为image.jpg(DOMString)
httpMethod:使用的HTTP方法 - PUT或POST。默认为POST(DOMString)
mimeType:要上传的数据的mime类型。默认为image / jpeg。 (DOMString)
params:在HTTP请求中传递的一组可选键/值对。 (Object,key / value - DOMString)
chunkedMode:是否以分块流模式上传数据。默认为true。 (布尔)
头:头名称/头值的映射。使用数组来指定多个值。在iOS,FireOS和Android上,如果存在名为Content-Type的标题,则不会使用多部分表单数据。 (Object)

查看此

对于您的第二个问题,请尝试获取错误代码在第二个问题中,您可以通过cordova-plugin-file-transfer =nofollow>链接获取更多信息。错误回调函数,并尝试缩小问题。



更新:我想使用文件传输插件无法进行FTP上传。插件定义本身表示FileTransfer对象提供了一种使用HTTP多部分POST或PUT请求上传文件并下载文件



您可能需要查看 ftp客户端的ftp上传。


I am trying to upload image to my FTP.

what i have achived so far is in this plnkr

my cordova file transfer 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 response of 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 button TakePicture which will take the pic and show to the user and also I have a function to upload using cordovafiletransfer $scope.upload .

my ftp host is ftp://308.3d8.myftpupload.com/ username and password is given in my coding in this i have a folder name called gopi where my image should store.

my path of the image taken is in imageURI parameter so i used services to set the path.

steps I’m in confusion

1) I am not able to understand the var options object in cordova file transfer plugin.

2) I am not getting any erro while remote debugging but i am only invoking my error funtion in my cordova file transfer.

How can i update my taken image to FTP using IONIC

UPDATE

Thanks to gandhi's answer https://github.com/xfally/cordova-plugin-ftp some how i managed to connect to ftp without multipart.

but sill facing error in this

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

i don't know what to in the first argument and second.

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

the above line success fully posted to my ftp but i am not able to post my image which is stored in my ping variable.

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

解决方案

The answer to your first question is available in the official documentation of file transfer plugin. The excerpt is as follow,

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)

Check out this link for more info.

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

Update: I guess ftp upload is not possible using 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 have to look at this for ftp client for ftp uploads.

这篇关于如何使用ngcordova文件传输插件传输拍摄的图像到我的FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆