On 5/11/19 11:07 AM, Shlomi Fish wrote:
Hi hwilmer,
On Fri, 10 May 2019 19:09:50 +0200
hwilmer <h...@gc-24.de> wrote:
Hi,
I would like to use curl to retrieve an image from a web server which I
want to store in a table in a mariadb database without downloading the
image to a file. For this application, I do not want to store
references to files stored in some file system instead.
So I would want to use something like
my $binary_data = `curl -k "https://www.example.com/some.jpg"`;
Perl distinguishes between 8-bit/binary strings and unicode ones. See
https://perldoc.perl.org/perlunitut.html .
What kind of string do I get when using backticks like in the above
example? One that perl considers as a text string I could use stuff
like uc or lc on, or as a binary string I could use pack or unpack on?
Variables are without types, so there is no way to tell. If I was using
curl to receive a text string, how would I know which encoding is being
used? For all I know that could depend on the machine my program is
running on after lots of factors I would never know about. And this
same encoding could happen to the image data.
Why would I use pack or unpack on the image data curl puts into the
string? Do I need to worry that somewhere --- like in my program or in
some method DBI provides or somewhere else --- some kind of string
transformation might take place that damages the image data? Is there a
way to tell perl that this is actually not a string but some binary data
that must not be transformed or encoded?
So far, it's working, but that could be just luck ...
Note however that you should see https://perl-begin.org/uses/web-automation/
and use a module instead of trapping curl.exe's output. Perl has bindings to
libcurl too if that is what you want.
First I tried to use WWW::Mechanize, and that failed because it can't
deal witch the self-signed certificates the web server is using. I
couldn't find anywhere in the documentation how to allow such
certificates. Otherwise it seemed to be able to do what I wanted.
Using curl via the library bindings is somewhat going to lengths I would
rather avoid.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/