Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public remotefile uploadFile(string fullPath)
- {
- //facts about file in question..
- FileInfo fileToUpload = new FileInfo(fullPath);
- string file64 = Utility.getCloudName(fileToUpload.FullName, Folder_Path);
- //url building
- string url = urlUpload;
- string postData = "?username=" + s.Email;
- postData += "&password=" + s.Password;
- postData += "&filesize=" + fileToUpload.Length.ToString();
- postData += "&filepath=" + file64;
- postData += "&crc=" + Utility.getCRC(fullPath);
- postData += "&content-type=" + Utility.getMimeFromFile(fullPath);
- postData += "&computer=" + Environment.MachineName.ToString();
- WebRequest wr = WebRequest.Create(url + postData);
- wr.Timeout = iTimeOut; //30min
- wr.Method = "PUT";
- wr.ContentType = "application/octet-stream";
- wr.ContentLength = fileToUpload.Length;
- Stream strm = wr.GetRequestStream();
- using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
- {
- int count = 0;
- for (int i = 0; i < fileToUpload.Length; i++)
- {
- count++;
- strm.WriteByte((byte)fs.ReadByte());
- }
- }
- strm.Close();
- //get response and parse it.
- WebResponse ws = wr.GetResponse();
- StreamReader sr = new StreamReader(ws.GetResponseStream());
- string strResponse = sr.ReadToEnd();
- parseResponse(strResponse);
- Debug.WriteLine(strResponse);
- Byte[] bytes = Encoding.ASCII.GetBytes(strResponse);
- MemoryStream ms = new MemoryStream(bytes);
- StreamReader srm = new StreamReader(ms);
- remotefile rf = new remotefile();
- XmlSerializer xs = new XmlSerializer(rf.GetType());
- rf = (remotefile)xs.Deserialize(srm);
- ws.Close();
- return rf;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement