小编Ben*_*oft的帖子

Node.js SendGrid 如何附加 PDF

我正在使用SendGrid在我的 Node.js 应用程序中发送电子邮件。我尝试附加 pdf 的每个组合都以我附加的 pdf 不可读而告终。

我试过了:

fs.readFile('public_html/img/Report.pdf',function(err,data){
    var base64data = new Buffer(data).toString('base64');

    sendgrid.send({
        to        : hexDecode(_.e),
        from      : 'xxxxxxxxx@gmail.com',
        subject   : 'Report',
        
        files      : [{filename:'Report.pdf',content:'data:application/pdf;base64,'+base64data}],
        // files   : [{filename:'Report.pdf',contentType:'data:application/pdf',url:'public_html/img/'Report.pdf'}],
        // files   : [{filename:'Report.pdf',url:'public_html/img/'Report.pdf'}],
        html       : 'bla bla'
Run Code Online (Sandbox Code Playgroud)

有谁知道如何防止“无法加载pdf文档”??

pdf email-attachments node.js sendgrid

3
推荐指数
3
解决办法
2万
查看次数

令人费解的正则表达式匹配古怪

var creatingidmatch='website.com'.match(/.idv.tw|.firm.in|.gen.in|.nom.es|.nom.co|.me.uk|.net.ag|.net.br|.net.bz|.net.co|.net.in|.net.nz|.com.ag|.com.br|.com.bz|.com.co|.com.es|.com.mx|.com.tw|.org.ag|.org.tw|.org.in|.org.uk|.org.nz|.org.es|.co.in|.co.uk|.co.nz|.asia|.mobi|.info|.com|.org|.net|.jobs|.biz|.xxx|.ca|.mx|.tv|.ws|.ag|.am|.at|.be|.bz|.cc|.de|.es|.eu|.fm|.fr|.gs|.in|.it|.jp|.ms|.nl|.nu|.se|.tc|.tk|.tw|.vg|.me|.co|.us/gi);
alert(creatingidmatch);
Run Code Online (Sandbox Code Playgroud)

这回来了

sit,.com
Run Code Online (Sandbox Code Playgroud)

'坐'来自哪里?(或者更确切地说,为什么它会返回我的字符串中的'sit'部分?)

javascript regex

2
推荐指数
2
解决办法
76
查看次数

PHP cURL 请求正文在 Node.js 中未定义

我已经尝试过这些帖子中的所有示例:

如何使用 PHP 发送 POST 请求?

PHP cURL Post 请求不起作用

我看到我的 request.body 始终undefined在请求本身中"_hasBody":true

我的 php post 文件的当前代码:

function httpPost($url,$data){
    $curl = curl_init($url);
    curl_setopt($curl,CURLOPT_POST,true);
    curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($data));
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
    $response=curl_exec($curl);
    curl_close($curl);
    return $response;
    }
$fields = array(
    'name' => 'ben'
,   'foo'  => 'bar'
    );
echo httpPost("http://localhost:8002", $fields);
Run Code Online (Sandbox Code Playgroud)

那么我的node.js监听服务器代码是:

var test=require('http').createServer(function(q,a){//question,answer
    console.log(q.body);
    console.log(JSON.stringify(q).indexOf('ben'));
    a.end(JSON.stringify(q));
    });
test.listen(8002,function(e,r){console.log("listening");});
Run Code Online (Sandbox Code Playgroud)

如您所见,在 node.js 服务器中,我在请求中搜索我的名字,但控制台显示

undefined//no body
-1//could not find your name in the request
Run Code Online (Sandbox Code Playgroud)

然后我将请求转回响应并将其打印到页面,以便我可以看到整个数据。

从逻辑上讲,我似乎正在按照复制的代码正确执行 cURL 部分,所以我想说我可能在访问变量时做错了什么

我的问题是如何查看请求正文或变量在哪里?

php curl node.js

2
推荐指数
1
解决办法
1752
查看次数

html5 canvas是否支持带alpha的十六进制颜色?

我想知道如果一个正方形可以用彩色绘制,#FF000000然后是一个圆圈#00000000

这将是绘制一个带有黑色像素的正方形,然后绘制一个带有透明像素的圆圈.

据我所知,十六进制颜色基本是红色,绿色,蓝色,但看起来你可以有类似的格式,rgba但像argb十六进制一样,00完全透明且FF坚固.

它在png中是有意义的,当你可以有透明像素时,alpha值也应该转换为十六进制作为合法和操纵值.

有8个字符的十六进制颜色看起来并不标准(通常是6长)因为我今天在Android应用程序上第一次看到它们并且想知道它们是否(想要更好的措辞 - 请编辑,如果不清楚)合法.

这是一种合法的颜色#00000000吗?这将是无形的,但在那里的黑色,因为这是我的理解纯黑色:#FF000000;

javascript hex canvas

1
推荐指数
2
解决办法
3256
查看次数

标签 统计

javascript ×2

node.js ×2

canvas ×1

curl ×1

email-attachments ×1

hex ×1

pdf ×1

php ×1

regex ×1

sendgrid ×1