1

I am using a web service to get some images dynamically generated and sent to my app. The problem is the file names tend to get super long based on all of the parameters I use to generate the images. Now I am running into situations where all of the parameters lead to names longer than 255 characters.

So I need a way to shorten them and also make sure they stay unique, similar to what bit.ly does but I need it accomplished on the device. As long as the final names are less than 255 characters I am good.

Not sure of how to accomplish this.

Slee
  • 27,498
  • 52
  • 145
  • 243
  • I think you should work it out in server, instead of in App, as web forwarding happens in web server. – Raptor Feb 06 '13 at 02:27

2 Answers2

7

When you have a lot of data, and you want to fingerprint it, or get some unique value back = hash.

You can sha1 or md5 your filename, and don't worry about collisions unless you are building a nuclear powerplant, or going to crash a rover on mars.

That or a lookup with a guid or incrementing number.

fionbio
  • 3,368
  • 2
  • 23
  • 38
  • Or do it on the server, returning an HTTP redirect to the short name and the actual asset at the short name? For which you could probably just use bit.ly, or an equivalent service with an API if it doesn't have one. – Tommy Feb 06 '13 at 02:11
  • MD5 (and maybe SHA1) guides: [MakeBetterThings.com](http://www.makebetterthings.com/iphone/how-to-get-md5-and-sha1-in-objective-c-ios-sdk/), [MobileDeveloperTips.com](http://mobiledevelopertips.com/core-services/create-md5-hash-from-nsstring-nsdata-or-file.html), [XAppSoftware.com](http://www.xappsoftware.com/wordpress/2012/04/26/how-to-use-sha1-and-md5-in-ios-applications/) – question Feb 06 '13 at 02:12
  • works like a champ, good samples here: http://stackoverflow.com/questions/652300/using-md5-hash-on-a-string-in-cocoa – Slee Feb 06 '13 at 12:26
0

Yes, Your desires are fulfilled :)

There is... Bitlyzer for iOS - "Class to shorten URLs with Bit.ly on iOS"

You need just to set your Bitly API username and key

More info here

TonyMkenu
  • 7,597
  • 3
  • 27
  • 49