public byte[] DownloadFile(string remotePath) { string url = "http://bcs.duapp.com/" + _bucketName; if (remotePath == "/" || string.IsNullOrEmpty(remotePath)) { } else { url += remotePath; } string flag = "MBO"; string para = "?sign=" + flag + ":" + _appKey + ":"; string content = flag + "\n" + "Method=GET" + "\n" + "Bucket=" + _bucketName + "\n" + "Object=" + remotePath + "\n"; string sign = BaiduSignatureHelper.GetSignature(content, _appSecret); para = para + sign; //WebRequestHelper helper = new WebRequestHelper(url); url = url + para; //var result = helper.Get(url); byte[] returnByte; try { WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); /* * StreamHelper helper = new StreamHelper(); * Stream newStream = new Stream(); * helper.CopyStream(stream, newStream); * returnByte = helper.StreamToBytes(newStream); */ long length = response.ContentLength; returnByte = new byte[length]; stream.Read(returnByte, 0, (int)length); /* * MemoryStream stream = (MemoryStream)response.GetResponseStream(); * returnByte = stream.ToArray(); */ response.Close(); } catch (Exception ex) { throw ex; } return(returnByte); }
public Model.CloudDisk.CloudFileInfoModel GetCloudFileInfo(string remotePath) { string url = "http://bcs.duapp.com/" + _bucketName; //if (remotePath == "/" || string.IsNullOrEmpty(remotePath)) //{ //} //else //{ // url += remotePath; //} string flag = "MBO"; string para = "?sign=" + flag + ":" + _appKey + ":"; string content = flag + "\n" + "Method=GET" + "\n" + "Bucket=" + _bucketName + "\n" + "Object=/" + "\n"; //+ "Object=" + remotePath + "\n"; string sign = BaiduSignatureHelper.GetSignature(content, _appSecret); para = para + sign; WebRequestHelper helper = new WebRequestHelper(url); url = url + para; var result = helper.Get(url); BaiduFileInfo info = JsonHelper.DeserializeObject <BaiduFileInfo>(result); CloudFileInfoModel m = null; if (info != null) { foreach (BaiduObjectList obj in info.object_list) { if (obj.Object == remotePath) { m = new CloudFileInfoModel(); m.Bytes = Convert.ToDouble(obj.size); m.IsDir = obj.is_dir == "1"; m.Path = obj.Object; m.MD5 = obj.content_md5; break; } } } return(m); }
public SingleCloudDiskCapacityModel GetCloudDiskCapacityInfo() { /* * string url = "https://pcs.baidu.com/rest/2.0/pcs/quota"; * string para = "?method=info&access_token=" + _accessToken; * SingleCloudDiskCapacityModel m = new SingleCloudDiskCapacityModel(); * WebRequestHelper helper = new WebRequestHelper(url); * var result = helper.Get(url + para); * XmlNode node = JsonHelper.DeserializeToXmlNode(result); * m.TotalByte = Convert.ToDouble(node.ChildNodes[0].SelectSingleNode("quota").InnerText); * var comsumed = Convert.ToDouble(node.ChildNodes[0].SelectSingleNode("used").InnerText); * m.TotalAvailableByte = m.TotalByte - comsumed; * return m;*/ string url = "http://bcs.duapp.com/?"; string flag = "MBO"; string para = "sign=" + flag + ":" + _appKey + ":"; string content = flag + "\n" + "Method=GET" + "\n" + "Bucket=" + "\n" + "Object=/" + "\n"; string sign = BaiduSignatureHelper.GetSignature(content, _appSecret); para = para + sign; WebRequestHelper helper = new WebRequestHelper(url); var result = helper.Get(url + para); List <BaiduBucketInfo> info = JsonHelper.DeserializeObject <List <BaiduBucketInfo> >(result); SingleCloudDiskCapacityModel m = new SingleCloudDiskCapacityModel(); if (info != null) { foreach (BaiduBucketInfo one in info) { if (one.bucket_name == _bucketName) { m.TotalByte = Convert.ToDouble(info[0].total_capacity); var comsumed = Convert.ToDouble(info[0].used_capacity); m.TotalAvailableByte = m.TotalByte - comsumed; } } } return(m); }
public Model.CloudDisk.CloudFileInfoModel UploadFile(byte[] fileContent, string filePath) { string url = "http://bcs.duapp.com/" + _bucketName + filePath; string flag = "MBO"; string para = "?sign=" + flag + ":" + _appKey + ":"; string content = flag + "\n" + "Method=PUT" + "\n" + "Bucket=" + _bucketName + "\n" + "Object=" + filePath + "\n"; //+ "Object=" + remotePath + "\n"; string sign = BaiduSignatureHelper.GetSignature(content, _appSecret); para = para + sign; url = url + para; CloudFileInfoModel result = new CloudFileInfoModel(); try { WebRequest request = WebRequest.Create(url); request.Method = "PUT"; request.ContentLength = fileContent.Length; //request.GetRequestStream Stream newStream = request.GetRequestStream(); newStream.Write(fileContent, 0, fileContent.Length); // Close the Stream object. newStream.Close(); Stream stream = request.GetResponse().GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); result.Path = filePath; } catch (Exception ex) { //throw ex; result = null; } return(result); }
public int DeleteFile(string remotePath) { string url = "http://bcs.duapp.com/" + _bucketName; if (remotePath == "/" || string.IsNullOrEmpty(remotePath)) { } else { url += remotePath; } string flag = "MBO"; string para = "?sign=" + flag + ":" + _appKey + ":"; string content = flag + "\n" + "Method=DELETE" + "\n" + "Bucket=" + _bucketName + "\n" + "Object=" + remotePath + "\n"; string sign = BaiduSignatureHelper.GetSignature(content, _appSecret); para = para + sign; //WebRequestHelper helper = new WebRequestHelper(url); url = url + para; try { WebRequest request = WebRequest.Create(url); request.Method = "DELETE"; //request.GetRequestStream Stream stream = request.GetResponse().GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); } catch (Exception ex) { //throw ex; return(0); } return(1); }