加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何使用ngcordova文件传输插件将拍摄的图像传输到

发布时间:2020-12-17 18:09:16 所属栏目:安全 来源:网络整理
导读:我正在尝试将图像上传到我的FTP. 到目前为止我所获得的是这个plnkr 我的cordova文件传输看起来像 $scope.upload =function(){ var options = { fileKey: "file",fileName: "gopi",chunkedMode: false,mimeType: "image/jpeg",params : {'user_token':'Chandr
我正在尝试将图像上传到我的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'} // 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);
        });

    };

我对cordova文件的错误函数的响应如下

FileTransferError {code: 2,source: “file:///storage/sdcard0/Android/data/com.ionicframework.camera108827/cache/1462186990291.jpg”,target: “07001”,http_status: null,body: null…}body: nullcode: 2exception: nullhttp_status: nullsource: “file:///storage/sdcard0/Android/data/com.ionicframework.camera108827/cache/1462186990291.jpg”target: “07001”proto: Object

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

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

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

步骤我很困惑

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

感谢gandhi的回答https://github.com/xfally/cordova-plugin-ftp我如何设法连接到没有multipart的ftp.

但是在这方面面临着错误

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

我不知道第一个论点和第二个论点是什么.

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

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

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

解决方法

第一个问题的答案可以在文件传输插件的官方文档中找到.摘录如下,

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)

查看此link了解更多信息.

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

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

对于ftp上传,您可能需要查看ftp client.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读