Trying to use upload method through applescript

David EphronDavid Ephron Beginner grinnerRegistered Users Posts: 5 Beginner grinner
I have been experimenting with applescripts to test the xml rpc APIs.

I can get all the methods to work correctly except "upload". I wonder if anyone has had any success?

See the sample script below.

The upload method always gives me an error = 9 code (invalid album id), even though I have inspected the result of the getAlbums method and the albumid appears to be valid (it matches the number in the URL that navigates to the gallery in question through the normal web interface.)

Is it possible that some other problem is incorrectly mapping into this error code, e.g. the upload doesn't like the value of the base64 stream?

Thanks -

DE.

tell application "https://upload.smugmug.com/xmlrpc/"

set returnValue to call xmlrpc {method name:"loginWithPassword", parameters:{"#my e-mail here#", "#my password here#", "1.0"}}
set mySessionID to sessionid of returnValue

end tell

tell application "http://upload.smugmug.com/xmlrpc/"

set returnValue to call xmlrpc {method name:"getAlbums", parameters:{mySessionID}}
set targetAlbumName to "Test" -- this gallery already exists, created manually
set targetAlbumID to -1
repeat with i in returnValue
if the title of i = targetAlbumName then set targetAlbumID to albumid of i
end repeat
-- inspection of returnValue and targetAlbumID shows presence of album "Test" with albumid of 285994

set theCaption to "Caption Sample Text"
set theFileName to "B.jpg"

tell application "Finder" to set encodedStream to read alias "Cookie:Users:dephron:Desktop:Smugmug Upload:Test:B" -- a base64 encoded JPG file
set returnValue to call xmlrpc {method name:"upload", parameters:{mySessionID, targetAlbumID, theCaption, theFileName, encodedStream}}

end tell

Comments

  • onethumbonethumb SmugMug CEO & Chief Geek Administrators Posts: 1,269 Major grins
    edited November 19, 2004
    I have been experimenting with applescripts to test the xml rpc APIs.

    I can get all the methods to work correctly except "upload". I wonder if anyone has had any success?

    See the sample script below.

    The upload method always gives me an error = 9 code (invalid album id), even though I have inspected the result of the getAlbums method and the albumid appears to be valid (it matches the number in the URL that navigates to the gallery in question through the normal web interface.)

    Is it possible that some other problem is incorrectly mapping into this error code, e.g. the upload doesn't like the value of the base64 stream?

    Thanks -

    DE.

    tell application "https://upload.smugmug.com/xmlrpc/"

    set returnValue to call xmlrpc {method name:"loginWithPassword", parameters:{"#my e-mail here#", "#my password here#", "1.0"}}
    set mySessionID to sessionid of returnValue

    end tell

    tell application "http://upload.smugmug.com/xmlrpc/"

    set returnValue to call xmlrpc {method name:"getAlbums", parameters:{mySessionID}}
    set targetAlbumName to "Test" -- this gallery already exists, created manually
    set targetAlbumID to -1
    repeat with i in returnValue
    if the title of i = targetAlbumName then set targetAlbumID to albumid of i
    end repeat
    -- inspection of returnValue and targetAlbumID shows presence of album "Test" with albumid of 285994

    set theCaption to "Caption Sample Text"
    set theFileName to "B.jpg"

    tell application "Finder" to set encodedStream to read alias "Cookie:Users:dephron:Desktop:Smugmug Upload:Test:B" -- a base64 encoded JPG file
    set returnValue to call xmlrpc {method name:"upload", parameters:{mySessionID, targetAlbumID, theCaption, theFileName, encodedStream}}

    end tell

    Off the top of my head, it looks like maybe the base64 bit isn't work, but I don't know for sure.

    Is there any particular reason you're not using the HTTP POST w/XML-RPC reply method? That method has been tested more and is currently in use by a few applications, so we're positive it works.

    The base64 upload worked the last time I used it, but it's possible something has changed since then.

    Do you have a way to capture exactly what XML-RPC data you're sending me? I could dissect it and take a look...

    Don
  • onethumbonethumb SmugMug CEO & Chief Geek Administrators Posts: 1,269 Major grins
    edited November 19, 2004
    onethumb wrote:
    Off the top of my head, it looks like maybe the base64 bit isn't work, but I don't know for sure.

    Is there any particular reason you're not using the HTTP POST w/XML-RPC reply method? That method has been tested more and is currently in use by a few applications, so we're positive it works.

    The base64 upload worked the last time I used it, but it's possible something has changed since then.

    Do you have a way to capture exactly what XML-RPC data you're sending me? I could dissect it and take a look...

    Don

    I managed to find one of your XML-RPC uploads, and it looks like you're not properly following the spec for submissions. I updated the doc to make it more clear.

    You're sending your base64 JPG as a String, but in reality, it needs to be a base64 scalar. If you change your XML tag to say <base64> rather than <string> you should be all set.

    Let me know if that doesn't clear it up.

    Don
  • David EphronDavid Ephron Beginner grinner Registered Users Posts: 5 Beginner grinner
    edited November 19, 2004
    onethumb wrote:
    Is there any particular reason you're not using the HTTP POST w/XML-RPC reply method? That method has been tested more and is currently in use by a few applications, so we're positive it works.

    The only reason that I am using the XML-RPC method rather than the HTTP POST w/XML-RPC reply method is that I could easily figure out the syntax by looking at http://www.smugmug.com/hack/xmlrpc-upload and looking at the XML-RPC applescript documentation on apple's website.

    The instructions at http://www.smugmug.com/hack/xmlrpc-post are not clear at all to someone who hasn't written these kinds of applications before. Perhaps you could post an example of how to upload a single file with a specified pathname, albumid, and caption using applescript or from the MacOS X command line or as HTML file that can be invoked by opening in a web browser or some other easily accessible method?

    Thanks -

    DE.
Sign In or Register to comment.