title: iPhone: Error uploading audio wav bytes data to server
body: <p>I am developing an iOS application. I have to send an audio file to our server programmatically. I am using the following code to send an sample wav audio file to server. Our server accepts only audio file in signed bytes array format for receiving.</p>
  
  <pre><code>NSURL *urlPath = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"Crash" ofType:@"wav"]];
  NSString *wavbundlepath = [urlPath absoluteString];
  NSLog(@"wavbundlepath: %@",wavbundlepath);
  NSData *bytes = [wavbundlepath dataUsingEncoding:NSUTF8StringEncoding];
  NSLog(@"bytes: %@",bytes);
  
  NSString *recordPostLength = [NSString stringWithFormat:@"%d", [bytes length]];
  
  NSMutableString *urlstr = [NSMutableString stringWithFormat:@"%@", @"http://www.mywebserver/api/UploadFile?Name="];
  [urlstr appendString:@"crash"];
  [urlstr appendFormat:@"&amp;MemberID=%d", 0];
  [urlstr appendFormat:@"&amp;Type=%@",@"Recording"];
  [urlstr appendFormat:@"&amp;client=%@",@"ios"];
  NSLog(@"urlstr.......%@",urlstr);
  
  NSMutableURLRequest *recordRequest = [[NSMutableURLRequest alloc] init] ;
  [recordRequest setURL:[NSURL URLWithString:urlstr]];
  [recordRequest setHTTPMethod:@"POST"];
  [recordRequest setValue:recordPostLength forHTTPHeaderField:@"Content-Length"];
  [recordRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  [recordRequest setHTTPBody:bytes];
  
  NSURLResponse *recordResponse;
  NSError *recordError;
  NSData *recordResponseData = [NSURLConnection sendSynchronousRequest:recordRequest returningResponse:&amp;recordResponse error:&amp;recordError];
  NSString *recordResp = [[NSString alloc]initWithData:recordResponseData encoding:NSUTF8StringEncoding];
  
  NSLog(@"recordResp:%@", recordResp);
  </code></pre>
  
  <p>But the problem is, always receving "Input string is not correct." response error.</p>
  
  <p>I am not very much aware of uploading audio bytes to server. Could someone please check this code and tell me this is valid code or not for uploading a wav audio bytes array to server?</p>
  
  <p>Thank you.</p>
  
  <hr>
  
  <p><strong>UPDATED CODE</strong></p>
  
  <p>I tried below code as my server side engineer said not to have any other things post body, and it works fine and getting positive response. But, the server is not able to work with format NSData bytes (32 bit elements) what i'm sending, because server side its implemented to receive only array of bytes or signed bytes data format only.</p>
  
  <pre><code>NSURL *urlPath = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"Temp" ofType:@"wav"]];
  
  NSString *wavbundlepath = [urlPath absoluteString];
  NSLog(@"wavbundlepath: %@",wavbundlepath);
  
  NSData *bytes=[NSData dataWithContentsOfURL:urlPath];
  NSLog(@"bytes: %@",bytes);
  
  NSString *recordPostLength = [NSString stringWithFormat:@"%d", [bytes length]];
  
  NSMutableString *urlstr = [NSMutableString stringWithFormat:@"%@", @"http://www.myserver.com/api/UploadFile?Name="];
  [urlstr appendString:@"Temp"];
  [urlstr appendFormat:@"&amp;MemberID=%d", 0];
  [urlstr appendFormat:@"&amp;Type=%@",@"Recording"];
  [urlstr appendFormat:@"&amp;client=%@",@"ios"];
  NSLog(@"urlstr.......%@",urlstr);
  
  NSMutableURLRequest *recordRequest = [[NSMutableURLRequest alloc] init] ;
  [recordRequest setURL:[NSURL URLWithString:urlstr]];
  
  NSInputStream *dataStream = [NSInputStream inputStreamWithData:bytes];
  [recordRequest setHTTPBodyStream:dataStream];
  
  [recordRequest setHTTPMethod:@"POST"];
  
  NSURLResponse *recordResponse;
  NSError *recordError;
  NSData *recordResponseData = [NSURLConnection sendSynchronousRequest:recordRequest returningResponse:&amp;recordResponse error:&amp;recordError];
  
  NSString *recordResp = [[NSString alloc]initWithData:recordResponseData encoding:NSUTF8StringEncoding];
  NSLog(@"recordResp:%@", recordResp);
  recordResponceJson = [recordResp JSONValue]; 
  NSLog(@"recordResponceJson = %@",recordResponceJson);
  recId = [recordResponceJson valueForKey:@"ID"];
  NSLog(@"recId....%@", recId);
  </code></pre>
  
  <p>Could someone please guide me, how i can send array of bytes in this http post?</p>