Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Dec 2013

    How can upload audio file and get response C#

    Hi. i'm trying to POST audio file to my Web Service and get Response from Server. I search on Google but no answer for Windows Phone 8.
    So please help me or Anyone have sample source ?

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Oslo, Norway

    Re: How can upload audio file and get response C#

    If it is a Web Service, there should be a dedicated function for posting data.
    If you mean a HTTP request, consider searching for HttpWebRequest post with Google, perhaps adding wp8. Being audio or anything else file does not really matter, so do not put that part into a search, however putting binary there can help with filtering out the examples about posting URL encoded forms.

  3. #3
    Registered User
    Join Date
    Dec 2013

    Re: How can upload audio file and get response C#

    Thank Moderator, i'm try to search with your suggest but have problem here, i hope you will help me fix that

    P/s : I'm using ASP.NET 4.5 Web API

    Here my code POST file

    byte[] buffer;
            private async void Upload(StorageFile fileStream)
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://sv.volcanosoft.com:47581/api/SpeechRecognition?dataType=json"));
                request.Method = "POST";
                request.ContentType = "multipart/form-data";
                request.UseDefaultCredentials = true;
                var file = await fileStream.OpenReadAsync();
                byte[] audioDataBytes;
                audioDataBytes = new byte[file.Size];
                for (int i = 0; i < audioDataBytes.Length; i++)
                    audioDataBytes[i] = (byte)file.AsStreamForRead().ReadByte();
                const int MAX_URI_LENGTH = 32766;
                string base64audio = System.Convert.ToBase64String(audioDataBytes);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < base64audio.Length; i += MAX_URI_LENGTH)
                    sb.Append(Uri.EscapeDataString(base64audio.Substring(i, Math.Min(MAX_URI_LENGTH, base64audio.Length - i))));
                string uploadRequestString = sb.ToString();
                buffer = Encoding.UTF8.GetBytes(uploadRequestString);
                request.BeginGetRequestStream(new AsyncCallback(ReadCallback), request);
            private void ReadCallback(IAsyncResult asynchronousResult)
                HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
                // End the operation.            
                Stream postStream = request.EndGetRequestStream(asynchronousResult);
                postStream.Write(buffer, 0, buffer.Length);
                request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
            private void ResponseCallback(IAsyncResult asynchronousResult)
                HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse resp = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
                Stream streamResponse = resp.GetResponseStream();
                StreamReader streamRead = new StreamReader(streamResponse);
                string responseString = streamRead.ReadToEnd();
                Dispatcher.BeginInvoke(new Action(() => { MessageBox.Show(responseString); }));
                // Close the stream object.            
                // Release the HttpWebResponse.            
    And here my error on Web API Server
    Invalid 'HttpContent' instance provided. It does not have a 'multipart' content-type header with a 'boundary' parameter.
    Parameter name: content

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2013
    Dublin, Ireland

    Re: How can upload audio file and get response C#

    You could also try using Portable HttpClient (available via NuGet). It's higher level and uses HttpWebRequest under the covers, but far less code is required to simply upload or download a file, which may help you when you're debugging?

Similar Threads

  1. cant upload a w3c file
    By dj ron in forum Feedback - Nokia Developer Services & Infrastructure
    Replies: 3
    Last Post: 2011-10-31, 12:37
  2. call handling and response with audio file
    By geek11 in forum Symbian
    Replies: 6
    Last Post: 2010-09-01, 19:39
  3. HTTP Post - audio upload
    By em75dl07 in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2010-02-15, 14:25
  4. Audio Response
    By chief35 in forum Mobile Java General
    Replies: 1
    Last Post: 2009-03-02, 09:42
  5. Upload the file
    By shashidon in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2008-04-09, 05:49

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts