我正在将一个应用程序从phonegap 2.*更新到cordova 3.4现在运行顺畅,只有文件下载不起作用.
我需要从Internet(主机编辑)下载文件并将其存储为JSON文件,以便稍后处理内容.下载工作正常,文件将显示在文件系统中,但FileReader不会触发onloadend事件.
我试图像一些事情onprogress或onerror事件,也file.toURI和FileReader.readAsDataURL-毫无效果.有人有什么想法吗?
笔记:
app.log 可以看作是别名 console.logprint_r 在另一个文件中定义,工作正常完整代码(提取和缩短):
var fileTransfer = new FileTransfer();
var loadingStatus = 0;
fileTransfer.onprogress = function (progressEvent) {
// if we have the complete length we can calculate the percentage, otherwise just count up
if (progressEvent.lengthComputable) {
loadingStatus = Math.floor(progressEvent.loaded / progressEvent.total * 100);
} else {
loadingStatus++;
}
app.log('Transfer Progress: ' + loadingStatus);
};
fileTransfer.download(
encodeURI('http://www.example.com/export'),
'cdvfile://localhost/persistent/import.json',
function (file) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用mailgun发送带附件的邮件.邮件本身很好,但它缺少附件.同样在mailgun日志中,它显示正常,但附件数组为空.
我用example.com替换了我的凭证.该文件放在子目录中并且可读.
$filename = 'directory/example.pdf';
$parameters = array('from' => 'Example <example@mail.example.com>',
'to' => 'example@example.com',
'subject' => 'Subject',
'text' => 'This is just a test.',
'attachment[1]' => '@' . $filename);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/mail.example.com/messages');
curl_setopt($ch, CURLOPT_USERPWD, 'api:key-ThisIsJustARandomString');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)
我没有收到错误,这是$response:
string(103) "{
"id": "<20170514122638.8820.55203.4543B111@mail.example.com>",
"message": "Queued. Thank you."
}"
Run Code Online (Sandbox Code Playgroud)
在mailgun日志中没有列出附件:
"message": {
"headers": {
"to": "example@example.com",
"message-id": "20170514122638.8820.55203.4543B111@mail.example.com",
"from": "Example <example@mail.example.com>",
"subject": "Subject" …Run Code Online (Sandbox Code Playgroud)