将音频文件上传到服务器c#
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将音频文件上传到服务器c#相关的知识,希望对你有一定的参考价值。
如何使用HttpClient()将音频文件上传到服务器。我的音频文件格式是“testaudio.3gpp”我想用它来做
await httpClient.PostAsync(uploadServiceBaseAddress, content);
请建议我的解决方案。完整代码如下
string path = "sdcard/testaudio.3gpp";
var content = new MultipartFormDataContent();
var httpClient = new HttpClient();
var uploadServiceBaseAddress = "https://example.com/UploadaudioFile.aspx";
var httpResponseMessage = await httpClient.PostAsync(uploadServiceBaseAddress, content);
string resp = await httpResponseMessage.Content.ReadAsStringAsync();
我认为流内容或其他东西必须添加到内容变量中。
答案
怎么样的:
string path = "sdcard/testaudio.3gpp";
var content = new MultipartFormDataContent();
var audioContent = new ByteArraycontent(System.IO.File.ReadAllBytes(path));
audioContent.Headers.ContentType = MediaTypeHeaderValue.Parse("audio/3gpp");
content.Add(audioContent, "audio", "testaudio.3gpp");
var httpClient = new HttpClient();
var uploadServiceBaseAddress = "https://example.com/UploadaudioFile.aspx";
var httpResponseMessage = await httpClient.PostAsync(uploadServiceBaseAddress, content);
string resp = await httpResponseMessage.Content.ReadAsStringAsync();
以上是关于将音频文件上传到服务器c#的主要内容,如果未能解决你的问题,请参考以下文章
如何将图像、pdf、音频、视频和任何文件系统从 iphone 本地内存上传到服务器(API)