//WebClient上传音频文件

public string UploadVoice(string fileNamePath)

{

Voice model=new Voice();

string saveUrl="D:/test";

string fileName=fileNamePath.Substring(fileNamePath.LastIndexOf("\\")+1);

if(saveUrl.EndsWith("/")==false)

{

saveUrl=saveUrl+"/";

}

saveUrl=saveUrl+fileName;

//创建WebClient实例

WebClient myWebClient=new WebClient();

myWebClient.Credentials=CredentialCache.DefaultCredentials;

//要上传的文件

FileStream fs=new FileStream(fileNamePath,FileMode.Open,FileAccess.Read);

BinaryReader r=new BinaryReader(fs);

try

{

model.Name=fileName;

model.Path=saveUrl;

db.Voice.Add(model);

db.SaveChanges();

byte[] postArray=r.ReadBytes((int)fs.Length);

Stream postStream=myWebClient.OpenWrite(saveUrl,"PUT");

if(postStream.CanWrite)

{

postStream.Write(postArray,0,postArray.Length);

}

else

{

return "No Write.";

}

postStream.Close();

return fileName;

}

catch(Exception ex)

{

return "Error:"+ex.Message;

}

}

WebClient上传音频文件的更多相关文章

  1. Jmeter工具之上传图片,上传音频文件接口

    https://www.jianshu.com/p/f23f7fe20bf3 互联网时代的来临,不同手机上安装的APP,还是PC端的应用软件或多或多都会涉及到图片的上传,那么在Jmeter工具如何模拟 ...

  2. webclient上传下载文件

    定义WebClient使用的操作类: 操作类名称WebUpDown WebClient上传文件至Ftp服务: //// <summary> /// WebClient上传文件至Ftp服务 ...

  3. WebClient上传下载文件,小白篇

    WebClient的上传文件一直报错,各种百度各种稀奇古怪的东西,终于百度到一篇小白学习篇 转自: https://www.cnblogs.com/cncc/p/5722231.html 使用C#We ...

  4. php 上传音频文件并获取时长

    <input type="file" name="audio" id="voice_file" style="display ...

  5. 使用WebClient上传文件并同时Post表单数据字段到服务端

    之前遇到一个问题,就是使用WebClient上传文件的同时,还要Post表单数据字段,一开始以为WebClient可以直接做到,结果发现如果先 Post表单字段,就只能获取到字段及其值,如果先上传文件 ...

  6. 利用WebClient上传参数及文件流到远程ashx服务

    原文 利用WebClient上传参数及文件流到远程ashx服务 1 思路: WebClient.UploadFile()方法可以上传文件:UploadData()方法可以上传数据参数:如何合二为一既上 ...

  7. Winform上传下载文件代码

    using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...

  8. webclient上传数据到ashx服务

    1.上传参数 UploadData()方法可以上传数据参数,需要将所要上传的数据拼成字符. // 创建一个新的 WebClient 实例.    WebClient myWebClient = new ...

  9. ant design + react,自动获取上传音频的时长(react-audio-player)

    在后台管理项目中,用户要求上传音频,并且自动获取音频时长. 第一步, import { Upload, Button, Icon } from 'antd'; 第二步,在表单中使用 Upload 组件 ...

随机推荐

  1. C#编码标准

    一.命名约定 1.PascalCasting PascalCasing 每一个单词第一个字母大写,其余字母均小写.例如:FileAccess,ArraySegment等. 除了参数.变量.常量外,所有 ...

  2. 国内docker镜像

    daocloud:https://www.daocloud.io/ 网易蜂巢:https://c.163.com/

  3. Excel文件读写

    C#读写Excel的方式有好几种,具体参考文章: http://www.cnblogs.com/huipengkankan/archive/2011/07/28/2120407.html 昨天大致研究 ...

  4. NEC学习 ---- 布局 -三列, 左右定宽,中间自适应

    ---恢复内容开始--- 这个布局很牛掰, 我觉得学习价值很大. 通过这个的学习, 我发现, 能将简单的事情做好, 就距离成功不远了. 其实布局就是利用所学知识, 活用. 在没看这个之前, 发现自己的 ...

  5. UML聚合与组合

    http://www.cnblogs.com/shanwenbin/archive/2012/10/24/2737229.html UML聚合与组合 2012-10-24 15:35 by DayDa ...

  6. 解决ssh登录后闲置时间过长而断开连接

     ++++++++++++++++++++++++++++ #!/usr/bin/env bash password_5="Uxxx7"host_5="129.x.x.1 ...

  7. JS脚本文件的位置对页面加载性能影响以及无阻塞脚本(javascript)模式

    JS的阻塞特性:当<script>出现的时候,页面必须等待脚本文件的加载.解析.执行完毕后才能继续进行页面的渲染.不管脚本文件是以内联形式还是外部引入的形式出现在<script> ...

  8. Count Complete Tree Nodes || LeetCode1

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * s ...

  9. vmware centos下配置ip

    使用NAT模式 虚拟机网络连接使用NAT模式,物理机网络连接使用Vmnet8. 虚拟机设置里面--网络适配器,网络连接选择NAT模式. 虚拟机菜单栏-编辑-虚拟网络编辑器,选择Vmnet8 NAT模式 ...

  10. OnScrollListener回调分析

    new AbsListView.OnScrollListener() {       @Override   public void onScrollStateChanged(AbsListView ...