所以这就是我想走的路。
步骤 1) 服务器返回图片的 base64
步骤 2) 手机应用程序将 base64 转换为图像
步骤 3) 手机应用程序将图像保存到手机
步骤 4) 使用 cordova 应用程序获取图像的文件 URI
我已经可以执行第 1 步和第 4 步了。我的问题是尝试采用 base64 并将其转换为手机上的图像。我知道我可以在图像标签的源代码中使用 base64 来显示图像,但这对我不起作用。我需要一个文件 URI 与 cordova 上传调用一起使用(将 base64 发送到此调用在 android 中有效,但在 iOS 中无效)。
任何帮助,将不胜感激。大家迟到的圣诞节快乐!!:)
更新:
我一直在尝试下载图像而不是接收 base64 响应,以便为上传方法提供有效的文件 uri 而不是 base64:
var uri = encodeURI("<my_server>/public/assets/uploads/img_54a2b5b29912b.jpg");
var fileURL = "/sdcard/testCordova/file.png";
var ft = new FileTransfer();
var options = new FileUploadOptions();
var headers={'Authorization':authHeader};
ft.download(
uri,
fileURL,
function(entry) {
alert("download complete: " + entry.toURL());
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
},
true,
options
);
这会继续在 android 上返回错误代码 = 3(尚未在 iOS 上测试)。还是卡住了。