Reputation: 9
I want to upload an audio file from my iPhone app to webserver but when I convert it into NSData then it will take upto 30 to 40 min in conversion, so can you gave any better solution for it.
Upvotes: 0
Views: 2435
Reputation: 5183
1).To convert audio file to NSData:
NSString *audioFilePath = @""; // local path where audio stored
NSData *audioData = [[NSData alloc] initWithContentsOfFile:audioFilePath];
2).To upload audio file:
NSString *audioName = @"myAudio.caf";
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://someurl.aspx"]];
[request addData:audioData withFileName:audioName andContentType:@"audio/caf" forKey:@"audioFile"];
[request setDelegate:self];
[request setTimeOutSeconds:500];
[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];
[request startAsynchronous];
- (void)uploadRequestFinished:(ASIHTTPRequest *)request
{
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;
NSData *webData = [[NSData alloc] initWithData:[request responseData]];
NSString *strEr = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
}
- (void) uploadRequestFailed:(ASIHTTPRequest *)request
{
NSLog(@"responseStatusCode %i",[request responseStatusCode]);
NSLog(@"responseString %@",[request responseString]);
NSError *error = [request error];
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;
}
Upvotes: 2