Unfortunately, there aren't many tutorials and good documentation for the three20 on the Internet ... so here's how I finally got the job:
- (void) sendToWebsite { NSString* url = [[NSString stringWithFormat:kRequestURLPath, self.entityId] stringByAppendingString:@".json"] ; // Prep. the request TTURLRequest* request = [TTURLRequest requestWithURL: url delegate: self]; request.httpMethod = @"POST"; request.cachePolicy = TTURLRequestCachePolicyNoCache; // Response will be JSON ... BUT WHY DO I NEED TO DO THIS HERE??? request.response = [[[TTURLJSONResponse alloc] init] autorelease]; // Set a header value [request setValue:[[UIDevice currentDevice] uniqueIdentifier] forHTTPHeaderField:@"Device-UID"]; // Post a string [request.parameters setObject:self.entity_title forKey:@"entity_title"]; // Post some images for (int i = 0; i < [self.photos count]; i++) { // IS IT POSSIBLE TO ADD A PARAM NAME SO I CAN LOOK FOR THE SAME NAME // IN THE WEB APPLICATION REGARDLESS OF FILENAME??? [request addFile:UIImagePNGRepresentation([self.winnerImages objectAtIndex:i]) mimeType:@"image/png" fileName:[NSString stringWithFormat:@"photo_%i.png", i]]; } // You rails guys will know what this is for [request.parameters setObject:@"put" forKey:@"_method"]; // Send the request [request sendSynchronously]; }
Things I still do not understand (or find problematic):
- For a published file, how do I include the parameter name AND file name?
- What is the purpose of setting request.response = on what? I do not understand this.
source share