首页 新闻 会员 周边

要设计一个 多服务器多 文件上传的类库,可惜能力不足,还请大仙帮忙

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-01-03 10:50

需求是这样:

有5台服务器 A、B、C、D、E

A:(WEB)

B:(中转服务器:双线服务器 与A、C、D、E 通讯比较好 )

C、D、E 都是图片服务器

 

流程是这样:从A 上传文件,发送到  中转服务器 B ,B 服务器再 发送文件到 C、D、E 

配置信息基本都在 A 服务器上

 

配置文件为XML 的 如下:

 usn:账户 pwd:密码 ,用于安全验证

 

<!--domain: 可以通过此域名访问到 最终 图片-->


<node>
<!--中转服务器-->
<server key="相册图片" domain="photo.image.xx.com" url="http://123.33.45.56:88/upload.aspx" usn="xxx" pwd="xxx">
<!--服务器节点, 需要在 每台服务器上 预先 配置好站点-->
<add url="http://134.33.45.56:88/upload.aspx" usn="xxx" pwd="xxx"/>
<add url="http://134.33.45.57:88/upload.aspx" usn="xxx" pwd="xxx"/>
<add url="http://134.33.45.58:88/upload.aspx" usn="xxx" pwd="xxx"/>
</server>

<!--中转服务器-->
<server key="日志图片" domain="note.image.xx.com" url="http://123.33.45.56:88/upload.aspx" usn="xxx" pwd="xxx">
<!--服务器节点, 需要在 每台服务器上 预先 配置好站点-->
<add url="http://134.33.45.56:88/upload.aspx" usn="xxx" pwd="xxx"/>
<add url="http://134.33.45.57:88/upload.aspx" usn="xxx" pwd="xxx"/>
<add url="http://134.33.45.58:88/upload.aspx" usn="xxx" pwd="xxx"/>
</server>

<!--中转服务器-->
<server key="专题图片" domain="topic.image.xx.com" url="http://123.33.45.56:88/upload.aspx" usn="xxx" pwd="xxx">
<!--服务器节点, 需要在 每台服务器上 预先 配置好站点-->
<add url="http://134.33.45.56:88/upload.aspx" usn="xxx" pwd="xxx"/>
<add url="http://134.33.45.57:88/upload.aspx" usn="xxx" pwd="xxx"/>
<add url="http://134.33.45.58:88/upload.aspx" usn="xxx" pwd="xxx"/>
</server>
</node>

 

上述方法涉及到 3 组 服务器

第一组:web 服务器 
第二组:中转服务器 
第三组:图片服务器 

 

中转服务器 和 图片服务器 中 在web.config 中加入

<add key="usn" value="xxx"/>
<add key="pwd" value="xxx"/>


与 上面的 usn pwd 对应 用于验证

 

用到类的设计:

 1 //裁切类型
2 public class CutType{
3 int width;
4 int height;
5 string prefix;
6 public int Width{
7
8 }
9 public int Height{
10 }
11 public string Prefix{
12 }
13 }
14
15
16 //上传类
17
18 Upload upload = new Upload("相册图片");
19 //配置文件路径
20 upload.ConfigFilePath = Server.Mappath("upload.config");
21
22 CutType ct400x300 = new CutType();
23 ct400x300.Width = 400;
24 ct400x300.Height = 300;
25 ct400x300.Prefix = "400x300_"; // 设定缩略图 名称前缀
26
27 upload.AddCutType(ct400x300); //添加一个裁切400x300的
28
29 CutType ct900 = new CutType();
30 ct900.Width = 900; //宽度为900
31 ct900.Height = 0; //0 表示自动, 可省略
32
33 upload.AddCutType(ct900);//添加一个宽度为900的
34
35 upload.FolderName = "2011-12-01";// 设置文件的保存目录
36
37 System.Collections.Hashtable ht =upload.Submit(); //提交发送 给中转服务器
38
39 if(ht["status"].ToString()=="success"){
40 Response.Write("上传成功");
41 //上传后的文件的文件名
42 ht["filename"].ToString();
43 ht["PathUrl"].ToString();//文件的url 前缀 不带文件名(因为生成的有 400x300_文件名的);如:http://topic.image.xx.com/2011-12-01/
44 }



 

就是想这么简单的搞定 多服务器 多文件上传。

fun5的主页 fun5 | 初学一级 | 园豆:4
提问于:2011-12-01 20:06
< >
分享
所有回答(1)
0

修改了下代码:

 1 //裁切类型
2 public class CutType{
3 int width;
4 int height;
5 string prefix;
6 public int Width{
7
8 }
9 public int Height{
10 }
11 public string Prefix{
12 }
13 }
14
15
16 //上传类
17
18 Upload upload = new Upload("相册图片");
19 //配置文件路径
20 upload.ConfigFilePath = Server.Mappath("upload.config");
21
22 CutType ct400x300 = new CutType();
23 ct400x300.Width = 400;
24 ct400x300.Height = 300;
25 ct400x300.Prefix = "400x300_"; // 设定缩略图 名称前缀
26
27 upload.AddCutType(ct400x300); //添加一个裁切400x300的
28
29 CutType ct900 = new CutType();
30 ct900.Width = 900; //宽度为900
31 ct900.Height = 0; //0 表示自动, 可省略
32
33 upload.AddCutType(ct900);//添加一个宽度为900的
34
35 upload.FolderName = "2011-12-01";// 设置文件的保存目录
36
37 upload.onSuccess= EventSuccess;// 上传完成 事件
38
39
40 //上传完成执行的动作
41 private void EventSuccess(System.Collections.Hashtable ht ){
42 if(ht["status"].ToString()=="success"){
43 Response.Write("上传成功");
44 //上传后的文件的文件名
45 ht["filename"].ToString();
46 ht["PathUrl"].ToString();//文件的url 前缀 不带文件名(因为生成的有 400x300_文件名的);如:http://topic.image.xx.com/2011-12-01/
47 }
48 }
fun5 | 园豆:4 (初学一级) | 2011-12-01 20:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册