curl-users
base64-encoded image as form variable
Date: Tue, 24 Sep 2013 19:52:06 -0700
I'm writing a script that extracts images from email and uploads them to
facebook. As a result, I'm getting image data encoded in base64, and I'd
like to upload this data using curl without saving the image data to a
file on disk.
Here is the body of my email:
|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--
|
The following command works, but would require me to save the data to a
file on disk (which I'm trying to avoid)
|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
|
The following command does not work, but it's essentially what I want
|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
|
Obviously, the above command will not work. For one, I didn't specify
the encoding of the data as base64. Is it possible to specify the
encoding for just a single field or would I have to do it for the whole
message (requiring me to encode the |message| and |access_token| fields
as base64 too)?
In general, please tell me how to send a (base64 encoded) image via curl
without first saving the data to a file on disk.
TIA
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-09-25