简体   繁体   English

带有base64 img附件的电子邮件编辑器不起作用

[英]Email composer with base64 img attachment not working

I'm not a pro programmer but I'm trying to attach a img file using this plugin in a mobile web app. 我不是专业程序员,但我正在尝试使用插件在移动网络应用程序中附加img文件。

Now, the plugin says I have to do something like this to add an attachment 现在,插件说我必须做这样的事情才能添加附件

attachments: 附件:

'base64:icon.png//iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/...'

And my base64 img for example is: 以我的base64 img为例:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJ.......

which is saved in the var imgURI 保存在var imgURI中

I've tried to do attachment: "base64:icon.png//" + $rootScope.imgURI.substring(24), 我尝试做附件:“ base64:icon.png //” + $ rootScope.imgURI.substring(24),

And also without substring or with substring 25, 26. In every case the attachment isn'ìt passed to the email composer. 并且也没有子字符串或带有子字符串25、26。在每种情况下,附件都不会传递给电子邮件编写器。 to:, subject:, body:, are working fine. 到:,主题:,身体:,工作正常。

What am I doing wrong? 我究竟做错了什么? Can you please help me? 你能帮我么? Thanks 谢谢

you can use the imageData: 您可以使用imageData:

var options = {
  destinationType : Camera.DestinationType.FILE_URI,
  sourceType : Camera.PictureSourceType.CAMERA,
  allowEdit : false,
  encodingType: Camera.EncodingType.JPG,
  popoverOptions: CameraPopoverOptions
};

$cordovaCamera.getPicture(options).then(function(imageData) {

  $scope.fileURI = imageData;

}

And, in your cordova EmailComposer code you can do: 而且,在您的cordova EmailComposer代码中,您可以执行以下操作:

  var email = {
    app: 'gmail',
    to: YOUR_TO,
    cc: YOUR_CC,
    bcc: YOUR_BCC,
    attachments: [
      $scope.fileURI
    ],
    subject: YOUR_SUBJECT,
    isHtml: true
  };

  $cordovaEmailComposer.open(email).then(null, function () {
    console.log("user cancelled email");
  });

It works fine for me, I can see my attached image in my Gmail's mail, for example. 它对我来说很好用,例如,我可以在Gmail的邮件中看到附件图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM