article search result of 'aps.net' : 1

  1. 2012.05.05 [ASP.NET] 클라이언트가 멀티파트 보내고 서버가 받기 (77)

[ASP.NET] 클라이언트가 멀티파트 보내고 서버가 받기

 

 

 

 

 

 

참고 : http://www.scripter.co.kr/entry/c-MultipartUpload

클라이언트 :

string url = "http://someServerApp.aspx"; FileStream fs = File.Open(@"d:\a.jpg", FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); Dictionary<string, object> postParam = new Dictionary<string, object>(); postParam.Add("1stParam", "1stValue"); postParam.Add("2ndParam", "2ndValue"); postParam.Add("file", new MultiPartUpload.FileParameter(data , "abc.jpg" , "image/jpeg")); HttpWebResponse webResponse = MultiPartUpload.MultipartFormDataPost(url, "", postParam); StreamReader reader = new StreamReader(webResponse.GetResponseStream()); TraceBox.trace(reader.ReadToEnd()); webResponse.Close();

;

 

 

 

서버 :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.IO;
namespace SimpleRequest
{
    public partial class test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            print("post count : " + this.Request.Form.Count + Environment.NewLine);
            foreach (string str in Request.Form)
            {
                print("name : " + str + "     value : " + Request.Form[str]);
            }

            print("FileCount : " + Request.Files.Count);
            if (Request.Files.Count == 0)
                return;

            HttpPostedFile file = Request.Files[0];
            print("-- fileName : " + file.FileName);
            print("-- fileSize : " + file.InputStream.Length);
        }

        private void print(object str)
        {
            Response.Write(str.ToString() + Environment.NewLine);
        }
    }
}
;

 

Request.Files 에서 파일 스트림을 포함한 정보를 얻을수 있다.

Yamecoder 야매코더_
C# 2012.05.05 23:27
Powerd by Tistory, designed by criuce
rss