Hi,
I'm trying to create a simple perl upload script to interact with the Chevereto API.
I get the following errors:
Script Errors:
HTTP POST error code: 400
HTTP POST error message: Bad Request
Apache Error Log:
[Sun Apr 03 15:42:36.407725 2016] [:error] [pid 19919] [client 10.1.1.118:39702] PHP Warning: Missing boundary in multipart/form-data POST data in Unknown on line 0
[Sun Apr 03 15:42:36.419811 2016] [:error] [pid 19919] [client 10.1.1.118:39702] Invalid API v1 key.
I've tried different combinations of content-type without luck...
Any ideas?
I'm trying to create a simple perl upload script to interact with the Chevereto API.
I get the following errors:
Script Errors:
HTTP POST error code: 400
HTTP POST error message: Bad Request
Apache Error Log:
[Sun Apr 03 15:42:36.407725 2016] [:error] [pid 19919] [client 10.1.1.118:39702] PHP Warning: Missing boundary in multipart/form-data POST data in Unknown on line 0
[Sun Apr 03 15:42:36.419811 2016] [:error] [pid 19919] [client 10.1.1.118:39702] Invalid API v1 key.
I've tried different combinations of content-type without luck...
Any ideas?
Code:
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use MIME::Base64;
use JSON;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "http://photos.mysite.com/api/1/upload";
my $server_api_key = "xxxx";
my $img = "/mnt/mysite/IMGP0013.JPG";
#convert the image to base64
open (my $image, $img) or die "$!";
binmode $image;
my $raw_string = do{ local $/ = undef; <$image>; };
my $encoded = encode_base64( $raw_string );
close ($img);
# set custom HTTP request header fields
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('content-type' => 'application/json');
$req->header('content-type' => 'multipart/form-data');
# add POST data to HTTP request body
my %post_hash = ( key => $server_api_key, source => $encoded, format => "json" );
my $post_data = to_json( \%post_hash );
$req->content($post_data);
my $resp = $ua->request($req);
if ($resp->is_success) {
my $message = $resp->decoded_content;
print "Received reply: $message\n";
}
else {
print "HTTP POST error code: ", $resp->code, "\n";
print "HTTP POST error message: ", $resp->message, "\n";
}