无法使用cordova-plugin-file-transfer上传base64映像 [英] Can't upload base64 image using cordova-plugin-file-transfer

查看:733
本文介绍了无法使用cordova-plugin-file-transfer上传base64映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用cordova-plugin-file-transfer将我的映像以base64格式上传到我的服务器,直到现在它不工作。我的代码是这样的:

I'm trying to upload my image in base64 to my server using cordova-plugin-file-transfer and until now it's not working. My code is like this:

photoBase64 = photoBase64.replace('data:image/png;base64,', '');

var url = "http://MYURL.com/path";

var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = "photoName.png";
options.mimeType = "image/png";

var ft = new FileTransfer();

ft.upload(photoBase64, 
          encodeURI(url), 

          function(result) {

                console.log("Code = " + result.responseCode);
                console.log("Response = " + result.response);
                console.log("Sent = " + result.bytesSent);
                resolve("OK");
          }, 

          function(error) {

                alert("An error has occurred: Code = " + error.code);
                console.error("ERROR", error);
                console.log("upload error source " + error.source);
                console.log("upload error target " + error.target);
                reject("ERROR");
          }, 

          options);

我收到以下错误代码:

如何使用cordova-plugin-file-转移?

How can I upload image base64 using cordova-plugin-file-transfer?

提前感谢!

推荐答案

不采用Base64字符串。你必须使用文件的位置(file :: // android / etc)。有关文件插件获取文件的更多信息(这个插件与filetransfer插件自动安装)在这里:

The file transfer plugin doesn't take Base64 strings. You have to use the location of the file (file:://android/etc). More info about the File plugin to get the file (this plugin is automatically installed with the filetransfer plugin) is here:

https://github.com/apache/cordova-plugin-file

如果你真的想只使用base64字符串,你必须使用$ http.post并在接收端写一个api来重建文件

If you would really want to just use the base64 string, you would have to use $http.post and write a api on the receiving side to recreate the file

这篇关于无法使用cordova-plugin-file-transfer上传base64映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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