WebClient上传音频文件
//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上传音频文件的更多相关文章
- Jmeter工具之上传图片,上传音频文件接口
https://www.jianshu.com/p/f23f7fe20bf3 互联网时代的来临,不同手机上安装的APP,还是PC端的应用软件或多或多都会涉及到图片的上传,那么在Jmeter工具如何模拟 ...
- webclient上传下载文件
定义WebClient使用的操作类: 操作类名称WebUpDown WebClient上传文件至Ftp服务: //// <summary> /// WebClient上传文件至Ftp服务 ...
- WebClient上传下载文件,小白篇
WebClient的上传文件一直报错,各种百度各种稀奇古怪的东西,终于百度到一篇小白学习篇 转自: https://www.cnblogs.com/cncc/p/5722231.html 使用C#We ...
- php 上传音频文件并获取时长
<input type="file" name="audio" id="voice_file" style="display ...
- 使用WebClient上传文件并同时Post表单数据字段到服务端
之前遇到一个问题,就是使用WebClient上传文件的同时,还要Post表单数据字段,一开始以为WebClient可以直接做到,结果发现如果先 Post表单字段,就只能获取到字段及其值,如果先上传文件 ...
- 利用WebClient上传参数及文件流到远程ashx服务
原文 利用WebClient上传参数及文件流到远程ashx服务 1 思路: WebClient.UploadFile()方法可以上传文件:UploadData()方法可以上传数据参数:如何合二为一既上 ...
- Winform上传下载文件代码
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...
- webclient上传数据到ashx服务
1.上传参数 UploadData()方法可以上传数据参数,需要将所要上传的数据拼成字符. // 创建一个新的 WebClient 实例. WebClient myWebClient = new ...
- ant design + react,自动获取上传音频的时长(react-audio-player)
在后台管理项目中,用户要求上传音频,并且自动获取音频时长. 第一步, import { Upload, Button, Icon } from 'antd'; 第二步,在表单中使用 Upload 组件 ...
随机推荐
- 【iCore3 双核心板_FPGA】例程五:Signal Tapll实验——逻辑分析仪
实验指导书及代码包下载: http://pan.baidu.com/s/1bnNRfaB iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- HDU 3695 Computer Virus on Planet Pandora(AC自动机模版题)
Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 256000/1280 ...
- 最实用的IT类网站及工具大集合[转]
1.聚合数据 大家在开发过程中,可能会用到各种各样的数据,想找一些接口来提供一些数据.比如天气预报查询,火车时刻表查询,彩票查询,身份证查询等等.有了这个接口,直接调用即可.各种各样的API接口满足你 ...
- 使用 JavaScript 实现基本队列、优先队列和循环队列
1.基本队列的实现 基本队列的方法中,包含了 ①向队列(尾部)中添加元素(enqueue).②(从队列头部)删除元素(dequeue).③查看队列头部的元素(front).④查看队列是否为空(isEm ...
- Example Microprocessor Register Organizations
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION
- 使用paramiko模块远程登录并上传或下载文件
1.paramiko安装 1)安装PyCrypto2.6 for Python 2.7 64bit.地址:http://www.voidspace.org.uk/python/modules.shtm ...
- Fiddler---前端利器
摘要:Fiddler是一个不错的工具,可以用来调试HTTP协议.工具很强大,本篇根据现有使用总结了下,以后有更多使用再做补充. 在做HTTPS协议对接的时候,拿不到数据,不得不找个工具试下,确定是接收 ...
- leetcode_199 Binary Tree Right Side View
题目: Given a binary tree, imagine yourself standing on the right side of it, return the values of the ...
- javascript jsscript .js xml html json soap
javascript ecma标准的脚本语言用于 jsscript 微软标准的一种脚本语言 .js javascript或jsscript保存成文件的形式可用于在html里重复引用 jsscript只 ...
- [原创]java WEB学习笔记94:Hibernate学习之路---session 的管理,Session 对象的生命周期与本地线程绑定
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...