vendredi 31 juillet 2015

Upload thumbnail and original image to mySQL AFNetworking

I am using AFNetworking to upload images to a mySQL database via PHP from an iPhone app. Here is the code I am using:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",nil];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
CGFloat compression = 1.0f;
UIImage *image = _uploadImage.image;
NSData *imageData = UIImageJPEGRepresentation(image, compression);
int random = arc4random() % 9999999;
NSString *photoName=[NSString stringWithFormat:@"%d-image.jpg",random];
[manager POST:@"http://ift.tt/1fQm1gD" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData name:@"image" fileName:photoName mimeType:@"image/jpeg"];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {            
        NSLog(@"Success: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];

My question is - is it possible to use AFNetworking to save a thumbnail version as well as saving the original photo? If so, how would I go about this? Or would I have to use another library to achieve this? Will appreciate any help.

Aucun commentaire:

Enregistrer un commentaire