我想将我的iPhone应用程序中的音频文件上传到网络服务器,但是当我将其转换为NSData时,转换时间最多需要30到40分钟,所以你能为它提供更好的解决方案。
答案 0 :(得分:2)
1)。要将音频文件转换为NSData:
NSString *audioFilePath = @""; // local path where audio stored
NSData *audioData = [[NSData alloc] initWithContentsOfFile:audioFilePath];
2)。上传音频文件:
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;
}