gpt4 book ai didi

iphone - 如何在 iPhone 的网络服务器上上传最大 5 MB 的 mp3 文件

转载 作者:行者123 更新时间:2023-11-28 22:51:33 25 4
gpt4 key购买 nike

我想从我的 iPhone 应用程序上传一个音频文件到网络服务器,但是当我将它转换成 NSData 时,转换过程最多需要 30 到 40 分钟,所以你能为它提供更好的解决方案吗?

最佳答案

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;
}

关于iphone - 如何在 iPhone 的网络服务器上上传最大 5 MB 的 mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11862273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com