• Gear
  • Shots
  • Photo Craft
  • Video
  • Wide Angle
  • Support
  • New Stuff
  • More
Support SmugMug APIs, Hacks & Tricks Non-OAuth Photo Upload with iOS???

Need some help with your New SmugMug Site?

Dgrin Challenges

Our Challenges moderator has lined up an new set of challenges for you. The Weekly Word Challenge. Get all the details and participate in the conversation Weekly Word Challenge.

Past DSS Challenge Winners, DSS Challenge Rules, and other important DSS Challenge information is here.

Looking for a little challenge? The Dgrin Mini-Challenges are a great way to challenge yourself. Take a moment to look through past winners and find the current Mini Challenge here.

From Around the Net

Enjoy a few of our favorite articles from around the 'net. If you have something you think we should see, post it here and we'll have a look.

Journeys

Landscapes

Sports

 
Thread Tools Display Modes
Old Apr-05-2013, 07:44 PM
#1
DrMillerKC is offline DrMillerKC OP
Big grins
Non-OAuth Photo Upload with iOS???
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.
Old Apr-08-2013, 05:18 PM
#2
devbobo is offline devbobo
LR whisperer
devbobo's Avatar
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
Old Apr-08-2013, 05:40 PM
#3
DrMillerKC is offline DrMillerKC OP
Big grins
Quote:
Originally Posted by devbobo View Post
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.

Quote:
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!
Old Apr-08-2013, 06:22 PM
#4
devbobo is offline devbobo
LR whisperer
devbobo's Avatar
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...

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
Old Apr-08-2013, 06:33 PM
#5
DrMillerKC is offline DrMillerKC OP
Big grins
Wow. Thanks for the direction! I was close but not close enough ;)
Old Apr-11-2013, 10:35 AM
#6
DrMillerKC is offline DrMillerKC OP
Big grins
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:

Code:
{"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.
Tell The World!  
Tags
api , ios , upload
Similar Threads Thread Starter Forum Replies Last Post
Public Album Photo Upload CameraRenter Legacy SmugMug Customization 2 Jun-11-2010 08:39 PM
Photo Upload Mistake JustPeachy2 Dgrin Forum Support 2 Nov-29-2009 04:59 PM
Upload Error - "ImageID" jhelms SmugMug Support 1 Jul-16-2008 08:21 PM
IE7 Crash During Photo Upload (Norton Not Involved) winterminute SmugMug Support 2 Aug-18-2007 09:10 AM
>>> LPS#10 Feedback thread Shay Stephens The Dgrin Challenges 57 Aug-13-2007 02:03 AM


Thread Tools
Display Modes

Posting Rules  
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump