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 02-24-2009, 02:56 AM   #23 (permalink)
demowolf
Registered Member
 
Join Date: Nov 2008
Posts: 10
Default

Quote:
Originally Posted by hijinks View Post
Here is a blog post about it

Post a UIImage to the web | Iphone Noob

Here is the meat of the code to post

Code:
NSData *imageData = UIImageJPEGRepresentation(image.image, 90);
	// setting up the URL to post to
	NSString *urlString = @"http://iphone.zcentric.com/test-upload.php";
	
	// setting up the request object now
	NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
	[request setURL:[NSURL URLWithString:urlString]];
	[request setHTTPMethod:@"POST"];
	
	/*
	 add some header info now
	 we always need a boundary when we post a file
	 also we need to set the content type
	 
	 You might want to generate a random boundary.. this is just the same 
	 as my output from wireshark on a valid html post
	*/
	NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
	NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
	[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
	
	/*
	 now lets create the body of the post
	*/
	NSMutableData *body = [NSMutableData data];
	[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];	
	[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"ipodfile.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
	[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
	[body appendData:[NSData dataWithData:imageData]];
	[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
	// setting the body of the post to the reqeust
	[request setHTTPBody:body];
	
	// 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];
I was courious why everybody stop talking about upload audio files , and talk about posting Images ?

I think it is easy and reliable to upload image through HTTP POST request .
But it's hard to upload big files, such as audio files, mp4 files. Can we do this still through HTTP POST ? I guess not so.

Even we can do this, is there some progress bar to know how much of this file has been transferred ?
demowolf is offline   Reply With Quote
 

» Advertisements
» Online Users: 621
23 members and 598 guests
ADY, Ashleyk27, Dattee, denied, falcondor, HowEver, iDifferent, ilmman, IphoneSdk, JasonR, john love, kampftrinker, klrichner, mapiko, mer10, mongoose250, Monstertaco, mylogon, peppinoss, smithdale87, timle8n1, walter_yaron
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,745
Threads: 89,200
Posts: 380,562
Top Poster: BrianSlick (7,129)
Welcome to our newest member, Ashleyk27
Powered by vBadvanced CMPS v3.1.0

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