ASI (from All-Seeing Interactive) is a great product.  Apple has made strides to incorporate some of the advanced procedures that this allows for, but ASI gives you some great features to easily handle some more complicated operations. It will allow you to easily download multiple files at once and aggregate the progress monitoring of these; It allowed for upload progress monitoring, before apple wired up its NSConnection objects for this purpose and many other features. Having said that I have run across a couple of scenarios and extensions to the basic code that I have found useful.

First I had the need to post multiple files in the same post request up to a web server. The ASI stack has a basic method for attaching an NSData object to your request data. This method simply takes in the data and assigns it “filename” as the default filename for the data that is passed in. Realistically there is no way for ASIFormDataRequest to infer the filename from the binary data. However, this can be quite useful when you are posting binary file data to a web service as the web service is often looking for unique filename identification of each binary part of the posted multipart-form request.

In order to enhance the ASIFormDataRequest to handle this scenario we simply modified the setData: forKey: method to have an override that sets the filename property.

- (void)setData:(NSData *)data forKey:(NSString *)key
	[self setData:data forKey:key withFilename:@"file"];

- (void)setData:(NSData *)data forKey:(NSString *)key withFilename:(NSString *)filename
	if (!fileData) {
		fileData = [[NSMutableDictionary alloc] init];
	NSMutableDictionary *file = [[[NSMutableDictionary alloc] init] autorelease];
	[file setObject:data forKey:@"data"];
	[file setObject:filename forKey:@"filename"];
	[fileData setValue:file forKey:key];
	[self setRequestMethod:@"POST"];

By adding the override on the method we have maintained the core functionality and extended it to allow for multiple files with multiple file names.