c#服务端接收客户端的文件上传,可以实现到断点续传
2013-07-29 16:16
465 查看
public void big_fileRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
bh = HttpContext.Current.Request["bh"].Trim();
string uploadPath = HttpContext.Current.Server.MapPath("dir");
if (!System.IO.Directory.Exists(uploadPath))
{
System.IO.Directory.CreateDirectory(uploadPath);
}
//CompilerSvr.MyFavoritesService compiler = new FDN.DMS.Controls.CompilerSvr.MyFavoritesService();
//compiler.Timeout = 2000000; //毫秒
string filename = bh + ".zip";
get_file_basestring(context);
byte[] buffer = Convert.FromBase64String(source);
FileStream fs = null;
if (tag == "0") //0开始,1续传
{
if (File.Exists(uploadPath + "/" + filename))
File.Delete(uploadPath + "/" + filename);
fs = new FileStream(uploadPath + "/" + filename, FileMode.OpenOrCreate, FileAccess.Write);
}
else
{
fs = new FileStream(uploadPath + "/" + filename, FileMode.Append, FileAccess.Write);
}
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}
public void get_file_basestring(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
System.IO.Stream inputStream = context.Request.InputStream;//这是你获得的流
byte[] buffer = new byte[inputStream.Length];
inputStream.Position = 0;
inputStream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区
//source = HttpContext.Current.Server.UrlDecode(source);//调用本地配置编码
//source.Length = 0;
source = HttpUtility.UrlDecode(Encoding.UTF8.GetString(buffer), Encoding.UTF8);//根据需要指定编码
}
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
bh = HttpContext.Current.Request["bh"].Trim();
string uploadPath = HttpContext.Current.Server.MapPath("dir");
if (!System.IO.Directory.Exists(uploadPath))
{
System.IO.Directory.CreateDirectory(uploadPath);
}
//CompilerSvr.MyFavoritesService compiler = new FDN.DMS.Controls.CompilerSvr.MyFavoritesService();
//compiler.Timeout = 2000000; //毫秒
string filename = bh + ".zip";
get_file_basestring(context);
byte[] buffer = Convert.FromBase64String(source);
FileStream fs = null;
if (tag == "0") //0开始,1续传
{
if (File.Exists(uploadPath + "/" + filename))
File.Delete(uploadPath + "/" + filename);
fs = new FileStream(uploadPath + "/" + filename, FileMode.OpenOrCreate, FileAccess.Write);
}
else
{
fs = new FileStream(uploadPath + "/" + filename, FileMode.Append, FileAccess.Write);
}
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}
public void get_file_basestring(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
System.IO.Stream inputStream = context.Request.InputStream;//这是你获得的流
byte[] buffer = new byte[inputStream.Length];
inputStream.Position = 0;
inputStream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区
//source = HttpContext.Current.Server.UrlDecode(source);//调用本地配置编码
//source.Length = 0;
source = HttpUtility.UrlDecode(Encoding.UTF8.GetString(buffer), Encoding.UTF8);//根据需要指定编码
}
相关文章推荐
- java实现的客户端向服务端上传文件的程序
- python socket上传文件的服务端和客户端实现
- C# TCP实现多个客户端与服务端 数据 与 文件的传输
- Python socket上传文件的服务端和客户端实现
- python socket上传文件的服务端和客户端实现
- 文件上传简单服务端和客户端 Java 实现
- [转载]C# TCP实现多个客户端与服务端 数据 与 文件的传输
- 请问 Android http上传文件 可以断点续传么 如果可以怎么实现 有第三方的插件么 谢谢
- java实现服务端守护进程来监听客户端通过上传json文件写数据到hbase中
- Android实现文件,图片上传,以及服务端接收相关。
- Android实现文件,图片上传,以及服务端接收相关。
- 使用TCP协议实现一个可以上传文件的客户端源代码(附详细注释)
- C# 实现 客户端 对实时数据的采集 上传至服务端;在服务端把保存到内存中;供WEB页面调用
- Python socket上传文件的服务端和客户端实现
- [通信] C# TCP实现多个客户端与服务端 数据 与 文件的传输
- MVC文件上传04-使用客户端jQuery-File-Upload插件和服务端Backload组件实现多文件异步上传
- python socket上传文件的服务端和客户端实现
- python socket上传文件的服务端和客户端实现
- JavaWeb从入门到放弃(9)-实现一个客户端上传文件到服务端
- 通过FTP服务端来实现匿名用户和基本用户的访问,可以实现文件上传和下载。通过web网站来浏览内容