I am using this code for audio file upload from iphone app to server.
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:mediaPath error: NULL];
NSLog(@"%@",fileAttributes);
if (fileAttributes != nil) {
NSNumber *fileSize;
fileSize = [fileAttributes objectForKey:NSFileSize];
NSLog(@"%@",fileSize);
// NSData *audioData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:audioData ofType:@""]];
NSString *urlString = [NSString stringWithFormat:@"%@audioupload.php",mydomainurl];
NSLog(@"%@",audioData);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"userfile\"; filename=\".caf\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:audioData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
Doing so it's converting the .caf file to binary and taking too much (1-2 mints) time to upload audio in server. Not only this the file size is getting bigger in server. I have included
ASIFormDataRequest
But don't know how to use this in my code. Can anyone suggest me that how can i reduce the upload time.
But