我正在编写一个脚本,从电子邮件中提取图像并将它们上传到 Facebook。结果,我得到了以 base64 编码的图像数据,我想使用 curl 上传这些数据,而不将图像数据保存到磁盘上的文件中。
这是我的电子邮件正文:
Content-Type: multipart/mixed;
boundary="------------030703050303060607000103"
This is a multi-part message in MIME format.
--------------030703050303060607000103
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
this message has a very small image of a single grey pixel attached to
it in jpeg format
--------------030703050303060607000103
Content-Type: image/jpeg;
name="grey.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="grey.jpg"
/9j/4AAQSkZJRgABAQEAAQABAAD/2wBDAP//////////////////////////////////////
////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFAAB
AAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAAAAF//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgB
AQABBQJ//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAGPwJ//8QAFBABAAAAAAAAAAAA
AAAAAAAAAP/aAAgBAQABPyF//9oACAEBAAAAEH//xAAUEAEAAAAAAAAAAAAAAAAAAAAA/9oA
CAEBAAE/EH//2Q==
--------------030703050303060607000103--
以下命令有效,但需要我将数据保存到磁盘上的文件中(我试图避免)
curl \
-F 'source=@pixel.jpg' \
-F 'message=this message has a very small image of a single grey pixel attached to it in jpeg format' \
-F 'access_token=<secret>' \
https://graph.facebook.com/<user_id>/photos
以下命令不起作用,但它本质上是我想要的
curl \
-F 'source=/9j/4AAQSkZJRgABAQEAAQABAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFAABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAAAAF//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABBQJ//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAGPwJ//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPyF//9oACAEBAAAAEH//xAAUEAEAAAAAAAAAAAAAAAAAAAAA/9oACAEBAAE/EH//2Q==' \
-F 'message=this message has a very small image of a single grey pixel attached to it in jpeg format' \
-F 'access_token=<secret>' \
https://graph.facebook.com/<user_id>/photos
显然,上面的命令是行不通的。一方面,我没有将数据的编码指定为 base64。是否可以只为单个字段指定编码,或者我必须为整个消息指定编码(要求我也将message
和access_token
字段编码为 base64)?
一般来说,请告诉我如何通过 curl 发送(base64 编码)图像,而无需先将数据保存到磁盘上的文件中。
TIA