- (void)uploadPost:(NSString *)imageURL {
// NSString *imageFilePath = [[NSBundle mainBundle] pathForResource:@"lion" ofType:@"jpg"];
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:postUrl parameters:nil constructingBodyWithBlock:^(id formData) {
[formData appendPartWithFileURL:[NSURL fileURLWithPath:imageURL] name:@"upfile" fileName:@"filename.png" mimeType:@"image/png" error:nil];
} error:nil];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[manager setResponseSerializer:[AFJSONResponseSerializer serializer]];
NSProgress *progress = nil;
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"%@", responseObject);
}
}];
[uploadTask resume];
} 做个小应用用nodejs或php做服务器还是挺好控制的,适合个人开发者啊!!!