Problem uploading multiple files on server. I am trying to upload multiple files on the server ,when i try this single file gets uploaded but multiple files do not.
I am using the following code but only single file gets uploaded .Please help me out.
********************************************************
NSArray *filePaths = NSSearchPathForDirectoriesInDomains (
NSDocumentDirectory,
NSUserDomainMask,
YES
);
NSString *path = [filePaths objectAtIndex: 0];
NSMutableURLRequest *urlRequest =[NSMutableURLRequest requestWithURL:url];
[urlRequest setHTTPMethod
"POST"];
[urlRequest setValue:[NSString stringWithFormat
"multipart/mixed; boundary=%@", boundry] forHTTPHeaderField
"Content-Type"];
NSMutableData *postData = [NSMutableData data];
for(int i=1;i<3;i++){
NSMutableString *filename = [[NSMutableString alloc]init];
[filename appendString
"Recording"];
[filename appendString:[NSString stringWithFormat
"%d",i]];
[filename appendString
".txt"];
NSMutableString *audioLoc = [[NSMutableString alloc] init];
[audioLoc appendString
ath];
[audioLoc appendString
"/"];
[audioLoc appendFormat
"%d",534];
[audioLoc appendString
"/Recording"];
[audioLoc appendString:[NSString stringWithFormat
"%d",i]];
[audioLoc appendString
".txt"];
NSData *file = [NSData dataWithContentsOfFile:audioLoc];
ASSERT(file);
if (!file) {
NSLog(@"file not found");
}
if ([file length] == 0) {
NSLog(@"file lenghth is zero");
}
[postData appendData:[[NSString stringWithFormat
"--%@\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithFormat
"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n\r\n", @"file",filename] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithString
"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[NSData dataWithContentsOfFile:audioLoc]];
[audioLoc release];
}
[postData appendData:[[NSString stringWithFormat
"\r\n--%@--\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];
/*//To send a single file
[postData appendData:[[NSString stringWithFormat
"--%@\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithFormat
"Content-Disposition: form-data; name=\"%@\"; filename=\"file.bin\"\r\n\r\n", FORM_FLE_INPUT] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:data];
[postData appendData:[[NSString stringWithFormat
"\r\n--%@--\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];
//To send a single file*/
NSString *s = [[NSString alloc] initWithData
ostData encoding:NSASCIIStringEncoding];
NSLog(@"The request body \n%@", s);
[urlRequest setHTTPBody
ostData];
return urlRequest;
***************************************************
I am using the following code but only single file gets uploaded .Please help me out.
********************************************************
NSArray *filePaths = NSSearchPathForDirectoriesInDomains (
NSDocumentDirectory,
NSUserDomainMask,
YES
);
NSString *path = [filePaths objectAtIndex: 0];
NSMutableURLRequest *urlRequest =[NSMutableURLRequest requestWithURL:url];
[urlRequest setHTTPMethod
[urlRequest setValue:[NSString stringWithFormat
NSMutableData *postData = [NSMutableData data];
for(int i=1;i<3;i++){
NSMutableString *filename = [[NSMutableString alloc]init];
[filename appendString
[filename appendString:[NSString stringWithFormat
[filename appendString
NSMutableString *audioLoc = [[NSMutableString alloc] init];
[audioLoc appendString
[audioLoc appendString
[audioLoc appendFormat
[audioLoc appendString
[audioLoc appendString:[NSString stringWithFormat
[audioLoc appendString
NSData *file = [NSData dataWithContentsOfFile:audioLoc];
ASSERT(file);
if (!file) {
NSLog(@"file not found");
}
if ([file length] == 0) {
NSLog(@"file lenghth is zero");
}
[postData appendData:[[NSString stringWithFormat
[postData appendData:[[NSString stringWithFormat
[postData appendData:[[NSString stringWithString
[postData appendData:[NSData dataWithContentsOfFile:audioLoc]];
[audioLoc release];
}
[postData appendData:[[NSString stringWithFormat
/*//To send a single file
[postData appendData:[[NSString stringWithFormat
[postData appendData:[[NSString stringWithFormat
[postData appendData:data];
[postData appendData:[[NSString stringWithFormat
//To send a single file*/
NSString *s = [[NSString alloc] initWithData
NSLog(@"The request body \n%@", s);
[urlRequest setHTTPBody
return urlRequest;
***************************************************