如何将音频文件从iphone文件夹上传到服务器

时间:2012-03-26 06:03:32

标签: iphone objective-c

我正在录制语音并将其保存到iphone文档文件夹中,但我希望它上传到服务器,那么该怎么做呢?

    NSString * path = [NSString stringWithFormat:@"%@/Documents/%@_%@_%@_%@.wav", NSHomeDirectory(), patient.firstName, patient.lastName, patient.transactionId, type];

路径为asset.path

 if (assetIndex < ([assets count]-1)) {
    while (assetIndex < ([assets count]-1)) {
        assetIndex += 1;
        Asset *asset = [assets objectAtIndex:assetIndex];
        NSData *data = [NSData dataWithContentsOfFile:asset.path];


     }

2 个答案:

答案 0 :(得分:0)

使用ASIHttpRequestjsonKit

  ASIFormDataRequest *request =  [ASIFormDataRequest requestWithURL:[NSURL URLWithString:kServerURLString]];
 [request setData:imageData
            withFileName:@"name.png" 
          andContentType:@"image/png"
                  forKey:@"file1"];
  [request setPostValue:@"yourJson" forKey:@"yourKey"];
  [request startSynchronous];
  NSError *localError = [request error];
  NSDictionary *responseDictionary = nil;
    if(!localError){
        responseDictionary = [[request responseString] objectFromJSONString];
         NSLog(@"ResponseDict:%@",[responseDictionary description]);
    }else{
        NSLog(@"Error:%@",[localError description]);
    }

答案 1 :(得分:0)