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

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

问题描述

我正在尝试将图像上传到我的 FTP.

I am trying to upload image to my FTP.

到目前为止我所取得的成就是在这个 plnkr

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

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

我有按钮 TakePicture 它将拍摄照片并显示给用户,而且我还有一个使用 cordovafiletransfer $scope.upload 上传的功能.

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 .

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

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.

我拍摄的图像路径在 imageURI 参数中,所以我使用服务来设置路径.

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

步骤我很困惑

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

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

2) 我在远程调试时没有收到任何错误,但我只是在我的科尔多瓦文件传输中调用我的错误函数.

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

如何使用 IONIC 将拍摄的图像更新到 FTP

How can i update my taken image to FTP using IONIC

更新

感谢甘地的回答 https://github.com/xfally/cordova-plugin-ftp 我是如何设法在没有多部分的情况下连接到 ftp 的.

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) {

$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) {

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

上述线路成功完全发布到我的 ftp,但我无法发布存储在我的 ping 变量中的图像.

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)

查看此链接了解更多信息.

对于第二个问题,尝试在错误回调函数中获取错误代码并尝试缩小问题范围.

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

更新:我猜想使用文件传输插件无法进行 ftp 上传.插件定义本身声明 FileTransfer 对象提供了一种使用 HTTP 多部分 POST 或 PUT 请求上传文件和下载文件的方法"

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"

对于 ftp 上传,您可能需要查看 ftp 客户端.

You may have to look at this for ftp client for ftp uploads.

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

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