Problem uploading using API
plympton
Registered Users Posts: 9 Beginner grinner
I'm running some test code to upload to SmugMug, but for some reason, nothing ever shows up in my test gallery. Is there a processing delay, and I should just check back... tomorrow? From what I can see, I'm not getting an error code in the response, so... what's up?
I seem to get a response_code of 200 no matter what I do - send like I think it should it send with random junk - invalid AlbumID, etc..
Anyone??
Got a Session ID
SessionID: 3ee89e6ebc6f898de042d63139c7145d
Hit Enter To Continue:
Changing to image directory...
Full starting path: /var/www/img/
Sending a photo to SmugMug via http_put...
Array
(
[Content-Length] => 85850
[Content-MD5] => aab322bf5c7f5f46ce5c519c046efa2c
[X-Smug-SessionID] => 3ee89e6ebc6f898de042d63139c7145d
[X-Smug-Version] => 1.2.0
[X-Smug-ResponseType] => JSON
[X-Smug-AlbumID] => 3469217
[X-Smug-FileName] => R1100GS-96.jpg
)
Response from server: Array
(
[effective_url] => http://upload.smugmug.com/R1100GS-96.jpg
[response_code] => 200
[total_time] => 0.888447
[namelookup_time] => 0.002016
[connect_time] => 0.031672
[pretransfer_time] => 0.031797
[size_upload] => 85850
[size_download] => 126
[speed_download] => 141
[speed_upload] => 96629
[header_size] => 353
[request_size] => 160
[ssl_verifyresult] => 0
[filetime] => -1
[content_length_download] => 126
[content_length_upload] => 85850
[starttransfer_time] => 0.069831
[content_type] => text/xml;charset=iso-8859-1
[redirect_time] => 0
[redirect_count] => 0
[connect_code] => 0
[httpauth_avail] => 0
[proxyauth_avail] => 0
[os_errno] => 0
[num_connects] => 1
[ssl_engines] => Array
(
[0] => dynamic
)
[cookies] => Array
(
)
[error] =>
)
Hit Enter To Continue:
Logging out of SmugMug...
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<method>smugmug.logout</method>
<Logout>
<Successful />
</Logout>
</rsp>Logged Out...
I seem to get a response_code of 200 no matter what I do - send like I think it should it send with random junk - invalid AlbumID, etc..
Anyone??
Got a Session ID
SessionID: 3ee89e6ebc6f898de042d63139c7145d
Hit Enter To Continue:
Changing to image directory...
Full starting path: /var/www/img/
Sending a photo to SmugMug via http_put...
Array
(
[Content-Length] => 85850
[Content-MD5] => aab322bf5c7f5f46ce5c519c046efa2c
[X-Smug-SessionID] => 3ee89e6ebc6f898de042d63139c7145d
[X-Smug-Version] => 1.2.0
[X-Smug-ResponseType] => JSON
[X-Smug-AlbumID] => 3469217
[X-Smug-FileName] => R1100GS-96.jpg
)
Response from server: Array
(
[effective_url] => http://upload.smugmug.com/R1100GS-96.jpg
[response_code] => 200
[total_time] => 0.888447
[namelookup_time] => 0.002016
[connect_time] => 0.031672
[pretransfer_time] => 0.031797
[size_upload] => 85850
[size_download] => 126
[speed_download] => 141
[speed_upload] => 96629
[header_size] => 353
[request_size] => 160
[ssl_verifyresult] => 0
[filetime] => -1
[content_length_download] => 126
[content_length_upload] => 85850
[starttransfer_time] => 0.069831
[content_type] => text/xml;charset=iso-8859-1
[redirect_time] => 0
[redirect_count] => 0
[connect_code] => 0
[httpauth_avail] => 0
[proxyauth_avail] => 0
[os_errno] => 0
[num_connects] => 1
[ssl_engines] => Array
(
[0] => dynamic
)
[cookies] => Array
(
)
[error] =>
)
Hit Enter To Continue:
Logging out of SmugMug...
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<method>smugmug.logout</method>
<Logout>
<Successful />
</Logout>
</rsp>Logged Out...
0
Comments
Here's the code I'm using to actually send the file. From all I've read, I'm sending the correct header information, and calculating the correct MD5 hash... so....? Also, it appears that changing the response-type does nothing to change the response... type.
-Dan
function put_file($sessionID,$upload_albumID, $local_dir, $upload_filename) {
$uploadURL = "http://upload.smugmug.com/".$upload_filename;
$upload_length = filesize($local_dir.$upload_filename);
$upload_MD5 = md5_file($local_dir.$upload_filename);
$request_options = array(
'Content-Length' => $upload_length,
'Content-MD5' => $upload_MD5,
'X-Smug-SessionID' => $sessionID,
'X-Smug-Version' => "1.1.1",
'X-Smug-ResponseType' => "REST",
'X-Smug-AlbumID' => $upload_albumID,
'X-Smug-FileName' => $upload_filename,
);
print_r ($request_options);
$response = http_put_file($uploadURL, $local_dir.$upload_filename, $request_options, $info);
return ($info);
}
I'm able to use the 1.2.0 API call for Upload_from_URL just fine, using almost the same parameters, and it worked perfectly, with a nice response.
Oh well. Moving forward!
Just for the record, this code works for uploading a file (php code):
function upload_from_url($params) {
$base = 'http://upload.smugmug.com/hack/rest/1.2.0/';
$query_string = '';
foreach ($params as $key => $value) {
$query_string .= "$key=" . urlencode($value) . "&";
}
$url = "$base?$query_string";
$xml = file_get_contents($url);
return ($xml);
}
$params = array(
'method' => "smugmug.images.uploadFromURL",
'APIKey' => "<myAPIkeyGetYourOwn>",
'AlbumID' => 3469217,
'SessionID' => $sessionID,
'Caption' => "Doooode",
'URL' => "http://www2.plymptonia.com/img/My_New_Beemer/R1100GS-96.jpg",
'ByteCount' => 85850,
'MD5Sum' => "aab322bf5c7f5f46ce5c519c046efa2c"
);
$xml = upload_from_url($params);
print_r($xml);
-Dan
I will check this out tomorrow....got off a 14 hours flight from Australia today and I can't really comtemplate looking at source right now
Cheers,
David
SmugMug API Developer
My Photos
Thanks I was getting a bit frustrated. :bash The UploadFromUrl call appears to work great, and I've been able to use other API calls as well (I can create Categories & fetch the responses). Since the HTTP_PUT process is different from the API, I assume I'm doing SOMETHING wrong.
Even just an error log would be awesome.
I'd be happy to post a note in the Wiki with my solution if I can get it to work.
Thanks!
-Dan
I have emailed you my SmugMug upload tester extension, can you have a play with that and confirm that HTTP Put works fine with the different response types.
Cheers,
David
SmugMug API Developer
My Photos