Writing your own uploader
One of the reasons I rewrote ecto from the ground up into what is now available as ecto3 beta is to allow for third-party add-ons. I wanted the application to become more modular and have a plug-in architecture. The first type of add-on that I am going to explain is the uploader. Some blog-systems allow users to upload files using either the appropriate XML-RPC or Atom call, but Blogger and a slew of others do not support that. For those alternative means should be available. ecto3 already has a built-in add-on that lets you upload images to Flickr. In this blog entry I will provide sample uploader code and directions on how to write your own. If you have the Cocoa skills, you could write an FTP or Picasa uploader.
The first step would be to download and unpack the sample uploader. It actually does not upload, but gives you a basic framework to work with. Once you've unpacked the sample, it's a good idea to rename the project. Let's assume your uploader will be called MyUploader. In the Finder, rename "SampleUploader.xcodeproj" to "MyUploader.xcodeproj". Double-click the file to open it. In the Groups & Files list, click on "SampleUploader" under the "Targets" section. Select File → Get Info. Under "Build", find the values for "Product Name" and "Prefix Header" and rename them. Under "Properties", assign a unique identifier, e.g. com.thirdparty.ecto_myuploader and change the principal class to "MyUploader". Close the Get Info window.
Back in Groups & Files, rename any files containing "SampleUploader" so that they contain "MyUploader". Rename the "SSUUploadWorker" files to something different as well. You will then have to rename the class names inside those files as well. In other words, class SampleUploader becomes MyUploader, and so forth.
Do NOT rename "UploaderInterface.h" and do NOT rename the "ECTOUploaderProtocol" protocol name.
In SampleUploader.m, you will also need to change the return value for "-(NSString*)uploaderKey
" and "-(NSString*)uploaderDescription
".
The uploader plug-in has two entry points. The first one is a method called when the user is accessing settings for a given attachment that uses the uploader: "-(id)uploaderRequested:(NSMutableDictionary*)settings
". You can use this to allow users to specify a variety of general preferences (which you would store in NSUserDefaults) or attachment-specific settings, which are stored in the provided dictionary. See SampleUploaderSettings.m for an example.
The actual upload happens with a call to -(void)uploadData:(NSDictionary*)data delegate:(id)del errorSelector:(SEL)err endSelector:(SEL)end statusSelector:(SEL)stat
. All the data you need for upload is provided in the "data" dictionary, which also includes any of the settings stored in the previously discussed method. The SampleUploader.m file lists the various available keys and how you can use them. It allocates an SUUploadWorker class, which does the actual upload. Once this object has done its job, a delegate call is made back to ecto to inform of the result. See -(void)upload
for an example of what you need to return to ecto.
The most simple adaptation would only require changing -(void)upload
in SUUploadWorker.m and writing code for the actual upload in there.
If you have any questions about writing an uploader, please visit the Developer support forum.
Reactions on this post