Ejemplo n.º 1
0
        private string UploadInternal(string path)
        {
            string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
            string pcsPath  = PcsPath;

            string[] pathComponents = path.Split(Path.DirectorySeparatorChar);

            int i = 0;

            foreach (var pathComponent in pathComponents)
            {
                if (i > 0)
                {
                    pcsPath += @"/" + pathComponent;
                }
                i++;
            }
            string url =
                "https://pcs.baidu.com/rest/2.0/pcs/file?method={0}&path={1}&access_token={2}";

            url = string.Format(url, BaiduCloudCommand.UploadCommand, Uri.EscapeDataString(pcsPath), AccessToken);
            string contentType = "multipart/form-data; boundary=" + boundary + "\r\n";
            var    response    = HttpWebResponseUtility.CreatePostHttpResponse(url, contentType, HttpWebResponseUtility.ConstructFileUploadPostData(path, pcsPath, boundary), HttpWebResponseUtility.DefaultRequestTimeout, null, Encoding.UTF8, null);

            return(HttpWebResponseUtility.ConvertReponseToString(response));
        }