急!怎么在asp.net中后台上传视频

ya0000 2011-04-22 12:34:13
最好是有代码的!谢了!成了!送积分!
...全文
101 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-04-22
  • 打赏
  • 举报
回复
可以考虑断点续传。。

上传
断点续传

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace CompleteClient
{
/// <summary>
/// 文件发送工作类
/// </summary>
class PostFile
{
/// <summary>
/// 通过post发送指定文件的指定字段到指定的uri上
/// </summary>
/// <param name="uploadfile">上传文件路径</param>
/// <param name="url">上传的到的URi位置</param>
/// <param name="offset">当前偏移量</param>
/// <param name="size">需要发送的块大小</param>
/// <param name="fileFormName">服务器端"GET"取得的文件名</param>
/// <param name="contenttype">文件类型(保留用)</param>
/// <param name="querystring">GET数组(供服务器用GET取得一些信息)</param>
/// <param name="cookies">本地cookies(保留用)</param>
/// <returns>uri的response的内容以string的形式返回</returns>
public string UploadFileEx(string uploadfile, string url, long offset, long size,
string fileFormName, string contenttype,
NameValueCollection querystring, CookieContainer cookies)
{
if ((fileFormName == null) ||
(fileFormName.Length == 0))
{
fileFormName = "file";
}

if ((contenttype == null) ||
(contenttype.Length == 0))
{
contenttype = "application/octet-stream";
}

string postdata;
postdata = "?";
if (querystring != null)
{
foreach (string key in querystring.Keys)
{
postdata += key + "=" + querystring.Get(key) + "&";
}
}
Uri uri = new Uri(url + postdata);

string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uri);
webrequest.CookieContainer = cookies;
webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
webrequest.Method = "POST";

// 构造一个post请求的http头
StringBuilder sb = new StringBuilder();
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
sb.Append("Content-Disposition: form-data; name=\"");
sb.Append(fileFormName);
sb.Append("\"; filename=\"");
sb.Append(Path.GetFileName(uploadfile));
sb.Append("\"");
sb.Append("\r\n");
sb.Append("Content-Type: ");
sb.Append(contenttype);
sb.Append("\r\n");
sb.Append("\r\n");

string postHeader = sb.ToString();
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);

// Build the trailing boundary string as a byte array
// ensuring the boundary appears on a line by itself
byte[] boundaryBytes =
Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");

FileStream fileStream = new FileStream(uploadfile,
FileMode.Open, FileAccess.Read);
long length = postHeaderBytes.Length + (long)size +
boundaryBytes.Length;
webrequest.ContentLength = length;

Stream requestStream = webrequest.GetRequestStream();
// 写入post头
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);

// 写入文件内容
byte[] buffer = new Byte[size];
fileStream.Seek(offset, SeekOrigin.Current);
fileStream.Read(buffer, 0, buffer.Length);

requestStream.Write(buffer, 0, buffer.Length);

// 写入post请求的尾
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
//读取服务器的反馈消息
WebResponse responce = webrequest.GetResponse();
Stream s = responce.GetResponseStream();
StreamReader sr = new StreamReader(s);

return sr.ReadToEnd();
}
}
}
小河 2011-04-22
  • 打赏
  • 举报
回复
传文件不就行了 不过视频一般很大 需要上传大文件 百度 上传大文件
xxoo2007 2011-04-22
  • 打赏
  • 举报
回复
COPY
孟子E章 2011-04-22
  • 打赏
  • 举报
回复
swfUpload
http://www.google.com/search?q=swfUpload&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:zh-CN:official&client=firefox-a
ya0000 2011-04-22
  • 打赏
  • 举报
回复
您说得好的!但是我没有看明白?
能有明白点的吗?

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧