0

I want to send an image to the server as a multipart data.

The data must be concated at the header part and not at the body part and the Content-Disposition: part must be left blank.

Any code is really appreaciated. Thanks in advance

For example

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

I want to append the data in the content type. How it can be done like for boundary there is boundary=%@ so for concating the data what keyword mus be used? _=%@.?

Suresh Varma
  • 9,750
  • 1
  • 60
  • 91

1 Answers1

0

Take a look at how TTURLRequest does it here:

http://google.com/codesearch/p?hl=en#paiB7gGbH1E/trunk/Projects/three20/src/TTURLRequest.m&q=TTURLRequest.m%20multipart&sa=N&cd=1&ct=rc

Or how ASIHTTPRequest does it here:

http://google.com/codesearch/p?hl=en#puVSP9AmSPI/Classes/ASIFormDataRequest.m&q=ASIHTTPRequest.m%20multipart&sa=N&cd=2&ct=rc

Better yet, use one of those two libraries to handle the multipart post for you.

esilver
  • 27,713
  • 23
  • 122
  • 168
  • Thanks esilver.. In both the case the image data is concatenated in the body part.. While I want to append it to header part.. Please let me knw hw it would be possible – Suresh Varma Apr 14 '11 at 07:26
  • Uhh, I don't think that is a good idea, aren't there size limitations to how big a header can be? Read this thread: http://stackoverflow.com/questions/1097651/is-there-a-practical-http-header-length-limit – esilver Apr 14 '11 at 07:40
  • Otherwise you could use this function from TTURLRequest.m and base64 encode your image into a string I guess: - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field { if (!_headers) { _headers = [[NSMutableDictionary alloc] init]; } [_headers setObject:value forKey:field]; } – esilver Apr 14 '11 at 07:41