Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. public remotefile uploadFile(string fullPath)
  2.         {
  3.             //facts about file in question..
  4.             FileInfo fileToUpload = new FileInfo(fullPath);
  5.             string file64 = Utility.getCloudName(fileToUpload.FullName, Folder_Path);
  6.             //url building
  7.             string url = urlUpload;
  8.             string postData = "?username=" + s.Email;
  9.             postData += "&password=" + s.Password;
  10.             postData += "&filesize=" + fileToUpload.Length.ToString();
  11.             postData += "&filepath=" + file64;
  12.             postData += "&crc=" + Utility.getCRC(fullPath);
  13.             postData += "&content-type=" + Utility.getMimeFromFile(fullPath);
  14.             postData += "&computer=" + Environment.MachineName.ToString();
  15.  
  16.             WebRequest wr = WebRequest.Create(url + postData);
  17.             wr.Timeout = iTimeOut; //30min
  18.             wr.Method = "PUT";
  19.             wr.ContentType = "application/octet-stream";
  20.             wr.ContentLength = fileToUpload.Length;
  21.  
  22.             Stream strm = wr.GetRequestStream();
  23.             using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
  24.             {
  25.                 int count = 0;
  26.                 for (int i = 0; i < fileToUpload.Length; i++)
  27.                 {
  28.                     count++;
  29.                     strm.WriteByte((byte)fs.ReadByte());
  30.                 }
  31.             }
  32.             strm.Close();
  33.             //get response and parse it.
  34.             WebResponse ws = wr.GetResponse();
  35.             StreamReader sr = new StreamReader(ws.GetResponseStream());
  36.             string strResponse = sr.ReadToEnd();
  37.             parseResponse(strResponse);
  38.  
  39.             Debug.WriteLine(strResponse);
  40.             Byte[] bytes = Encoding.ASCII.GetBytes(strResponse);
  41.             MemoryStream ms = new MemoryStream(bytes);
  42.             StreamReader srm = new StreamReader(ms);
  43.             remotefile rf = new remotefile();
  44.             XmlSerializer xs = new XmlSerializer(rf.GetType());
  45.  
  46.             rf = (remotefile)xs.Deserialize(srm);
  47.             ws.Close();
  48.             return rf;
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement