Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 10-22-2009, 10:28 AM   #4 (permalink)
dealyb
Registered Member
 
Join Date: Aug 2009
Posts: 5
Default Hi, Could you post the server side to this solution?

Hi, thanks for the code example. I was hoping you could pull the relevant code from the server side to show the complete end to end workings.
thanks in advance!
Brian

Quote:
Originally Posted by michelle View Post
I finally got this to work, the key was to make sure you load the image first.

You can see a storyboard of the process here.



- (IBAction)uploadImage {
/*
turning the image into a NSData object
getting the image back out of the UIImageView
setting the quality to 90
*/


UIDevice * dev = [UIDevice currentDevice];
NSString *uniqueId = dev.uniqueIdentifier;
NSString *name = @"photo1";
NSData *imageData = UIImageJPEGRepresentation(image.image, 90);
//NSData * imageData = UIImagePNGRepresentation(image);
// NSString *postLength = [NSString stringWithFormat:@"%d", [imageData length]];
NSString *urlString = [@"http://172.16.1.37:8080/tree-selection-tutorial/httpproxy?" stringByAppendingString:@"uid="];
urlString = [urlString stringByAppendingString:uniqueId];
urlString = [urlString stringByAppendingString:@"&name="];
urlString = [urlString stringByAppendingString:name];
urlString = [urlString stringByAppendingString:@"&lang=en_US.UTF-8"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSMutableData *postBody = [NSMutableData data];



//add data field and file data
[postBody appendData:[NSData dataWithData:imageData]];

// ---------

[request setHTTPBodyostBody];

// now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(returnString);
}

- (void)imagePickerControllerUIImagePickerControll er *)picker didFinishPickingImageUIImage *)img editingInfoNSDictionary *)editInfo {
image.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];

// need to show the upload image button now
upload.hidden = NO;
}

@end
dealyb is offline   Reply With Quote
 

» Advertisements
» Online Users: 287
17 members and 270 guests
ADY, apatsufas, chemistry, Fit4him, headkaze, ilmman, MarkC, marto1914, Meoz, PsychoChris, sly24, sneaky, Sunny46, tgjorgoski, Thrillhouse1919, timle8n1, vogueestylee
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,877
Threads: 89,222
Posts: 380,718
Top Poster: BrianSlick (7,129)
Welcome to our newest member, peterkessler45
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:00 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.