At MAX Adobe talked about Share, their new document storage/sharing service. It's relatively simple to use. You upload a file - set permissions - and then get some nifty little widgets. For example - you can upload a PDF and then get a Flash Paper preview you can embed in a web page. (I've done one below.) Images should also allow for embedding as well, but I believe there is a bug with the thumbnail. Anyway - this was cool in itself - but when I heard there was an API during the keynote, I immediately opened my browser to the docs. (API is about the only word that gets my attention more than wishlist.)
I was surprised to find that their API didn't just allow for simple listings but also allowed you to upload and download your documents. What does this mean? It means you can leverage the complete Share service completely from within your own application. (Although check the licensing - I didn't really read it well and I'm sure you have to credit Adobe somewhere.)
I worked on the API and had some difficulty. I got some help from the Share team (thank you Patrick Rodriguez and Fang Chang!) and I'm releasing my first version of the wrapper.
Before using this wrapper, you must ensure you have a valid Adobe ID. Then you must get your API key and shared secret from here.
Once you have this information you can then initiate a connection to Share:
<cfif not isDefined("application.share") or isDefined("url.reinit")> <cfset application.share = createObject("component", "share").init("firstname.lastname@example.org","parishiltonrules",appkey,sharedsecret)> </cfif>
You must persist the CFC so that the authentication/session information sticks. Otherwise the CFC will be pretty slow. That first hit to get set up takes about 2-3 seconds. Here is what you can do with my API:
This returns a query of information about the files and folders in your Share account. What I find cool is that folders, as far as I can tell, don't even show up on the Adobe site. Maybe I'm using the Flex app wrong, but I could only work with folders via the API. So the API actually lets you organize things even better than the public site! Example:
And this example lists files under a folder:
<cfdump var="#share.list('e0755f34-73b7-11dc-b75f-151d3f6d9313')#" label="List of stuff under my new folder">
Create New Folder
Does what it says. It can make a new folder at root or below another folder.
<cfset r = share.newFolder("new folder one2")>
Right now the result is a string. It will either be an error (if the folder already exists) or an XML packet for the node. I'm thinking of making it CFTHROW in case of a real error and for success doing nothing - or returning a structure representing the node. Comments?
DeleteThis deletes folders or files. Like above - I need to tweak the return logic a bit.
<cfset r = share.delete("9f801c1f-73b5-11dc-b75f-151d3f6d9313")>
Uploads a file. Example:
<cfset myfile = expandPath("./test.pdf")> <cfset r = share.upload(myfile,"Test upload")>
Downloads a file. Duh. Example:
<cfset destpath = expandPath(".") & "/" & replace(createUUID(), "-","_","all") & ".pdf"> <cfset share.download("dd5b6c48-7464-11dc-b75f-151d3f6d9313", destpath)>
- Rename is in there - but currently broken. Move is essentially the same and once I get rename done, I'll work on move.
- Permissions/Shares: I've done nothing in this area yet.
- Working with "file renditions" - which is a just a fancy way of making it easier for you to display stuff on your site. I'm thinking of something simple like this: <cfoutput>#share.renderPreview("nodeidhere")#<cfoutput>
You can download the zip below. It isn't explicitly stated in the file, but this code follows the same OS license I use for the rest of my code. Once I get the above finished, I'll be moving it to RIAForge.
And lastly - here is a sample embed of a PDF:
Edit: Removed preview as it was throwing errors.