我目前正在尝试通过我的本机应用程序从用户设备发送电子邮件。 这样做的过程很简单。用户填写一些输入字段,选择图片(新图片或来自图库)并继续通过电子邮件发送。 根据模块的文档,需要图片的绝对文件路径。
我得到的文件路径如下:
file:///Users/User/Library/Developer/CoreSimulator/Devices/909705DC-D5…119-75CC009FFA5C/Documents/images/6EC7EAA7-0D37-4909-ABC4-B5DE250ED968.jpg
我收到以下错误消息:
Exception '-[MFMailComposeInternalViewController addAttachmentData:mimeType:fileName:] attachment must not be nil.' was thrown while invoking mail on target RNMail with params (
{
attachment = {
name = Name;
path = "file:///Users/zser/Library/Developer/CoreSimulator/Devices/909705DC-D5…119-75CC009FFA5C/Documents/images/6EC7EAA7-0D37-4909-ABC4-B5DE250ED968.jpg";
type = jpg;
};
body = "<h1>Content</h1>";
isHTML = 1;
recipients = (
"reiceiver@mail.com"
);
subject = subject;
},
25
)
这条路有问题吗?
接下来应该接受文件作为附件的基本代码:
Mailer.mail({
subject: 'Subject',
recipients: ['receiver@mail.com'],
body: `<h1>Content</h1>`,
isHTML: true, // iOS only, exclude if false
attachment: {
path: that.state.absolute_path, // The absolute path of the file from which to read data.
type: 'jpg', // Mime Type: jpg, png, doc, ppt, html, pdf
name: 'Ladunek', // Optional: Custom filename for attachment
}
}, (error, event) => {
if(error) {
AlertIOS.alert('Error', 'Niestety mail nie zostal wyslany. Prosze przeslac manualnie mail na : receiver@mail.com');
}
})
感谢您的帮助
答案 0 :(得分:0)
显然从绝对路径中删除'file:///'
解决了问题。