Non-OAuth Photo Upload with iOS???

DrMillerKCDrMillerKC Registered Users Posts: 24 Big grins
I *had* planned a business where my mobile iOS app, used by scores of customers (none of whom would have a SmugMug account), would upload photos to a single, MY SmugMug account under individual Categories/SubCategories, and I would distribute revenue based on their sales. The mobile app is developed but the hurdle is figuring out with the API how they all can upload photos to MY account.

The latest API, 1.3, seems to be completely dependent, especially for uploads, on OAuth which is based on the model where individual users access THEIR SmugMug accounts without the app using their username/password. I don't see how I could use the latest API at all for my business model. The older API would seem to work better with my model (my username/password would be encrypted and safe on the device).

So, 1) is there anyway possible to use 1.3 and have end-users, who do not have a SmugMug account, upload photos to my account, 2) why can't I use an earlier API, and 3) does anyone know of *new* example code, especially for iOS/Objective-C for uploading to one SmugMug account?

Thanks for any tips and thoughts.

Comments

  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited April 8, 2013
    G'day Don,

    Firstly, uploading isn't necessarily tied to a given API version, you can upload using OAuth or SessionID.

    Secondly, instead of distributing the app with your username and password, you can instead distribute with an OAuth token/secret encrypted with the correct permissions/access in the same fashion. From a security perspective, that way your account is comprised if someone happens to decrypt your password stored on the device and if something ever happens, you can just revoke the OAuth token and issue a new one for your app to use.

    Hope this helps.

    Cheers,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • DrMillerKCDrMillerKC Registered Users Posts: 24 Big grins
    edited April 8, 2013
    devbobo wrote: »
    G'day Don,

    Firstly, uploading isn't necessarily tied to a given API version, you can upload using OAuth or SessionID.

    And secondly, thanks for the reply. I've basically programmed the app, and this is the last piece but I am flailing bad. I did figure out how to log on and actually got a SessionID and later got AlbumIDs! I did find accidentally this page after spending hours trying to figure out smugmug.images.uploadFromURL. Just couldn't figure out the URL on my device. I have spent the last several hours trying to use the information on that link, but I guess I'm missing many pieces.
    Secondly, instead of distributing the app with your username and password, you can instead distribute with an OAuth token/secret encrypted with the correct permissions/access in the same fashion.

    I don't have a clue how to do that (and if I did, do I stick to 1.2.2 or move to 1.3?). I thought that I would use my userID and persist the PasswordHash always using https. That I understand and seemed pretty secure to me (as long as the PasswordHash never changes).

    I basically want to copy the way Awesome Camera handles uploads, that is, show thumbnails, tap a couple, and then tap an Upload button. I would then want a progress spinner on each thumbnail to display progress and then to mark the thumbnail as they upload is complete. That's yet another challenge (maybe v2.0) although I'm also try to learn AFNetworking for Obj-C to shelter me from bare metal ;)

    Thanks again for any help you can provide!
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited April 8, 2013
    Don,

    Firstly, smugmug.images.uploadFromURL is method aimed at uploading images directly from other webservers or service on the web, rather than a device.

    Here's some sample code that I have cobbled together from a internet searches on the library you are using, I haven't written Obj-C in a little while and I don't really know this library, so it's probably more a guide than executable code...
    NSData *postData = [NSData dataWithContentsOfFile:_path]; // require _path for the file on disk
    NSURL *url = [NSURL URLWithString:@"http://upload.smugmug.com/"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    
    [request setHTTPMethod:@"POST"];
    [request setValue:_sessionId forHTTPHeaderField:@"X-Smug-SessionID"]; // require SessionID for uploading
    [request setValue:@"JSON" forHTTPHeaderField:@"X-Smug-ResponseType"];
    [request setValue:@"1.2.2" forHTTPHeaderField:@"X-Smug-Version"];
    [request setValue:[_path lastPathComponent] forHTTPHeaderField:@"X-Smug-FileName"];
    [request setValue:_albumId forHTTPHeaderField:@"X-Smug-AlbumID"];  // require AlbumID for the upload target
    
    [request setValue:[postData md5HexString] forHTTPHeaderField:@"Content-MD5"];
    [request setValue:NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
    [req setHTTPBody:postData];
    
    AFJSONRequestOperation *operation = [[[AFJSONRequestOperation alloc] initWithRequest:request] autorelease];
    
    // insert AFNetworking handlers here
    
    [operation start];
    

    I've made the assumption that's you are using JSON, if not you will need to modify as required.

    Hope this helps,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • DrMillerKCDrMillerKC Registered Users Posts: 24 Big grins
    edited April 8, 2013
    Wow. Thanks for the direction! I was close but not close enough ;)
  • DrMillerKCDrMillerKC Registered Users Posts: 24 Big grins
    edited April 11, 2013
    Well, I tried your code above and it works like a charm and successfully uploaded an image. But I tried a hundred times to upload other images, one at a time, using more AFNetworking multipart magic (progress on upload, multiple images, etc.), it show the progress of the upload, and even finishes the upload but I get back:
    {"stat":"fail","method":"smugmug.images.upload","code":5,"message":"system error"}
    

    And when I check the Upload log in SmugMug it says, "upload problem, invalid album". Well, it is the very same albumID that I can repeatedly use in your code (not multipart form-data).

    So, I'm at a lost whether the multipart AFNetworking stuff is the problem, or something on the SmugMug API end of things.

    Any thoughts?

    Thanks.
Sign In or Register to comment.