Beispiel #1
0
        private static WebHeaderCollection /*NameValueCollection*/ GetFormData(string upToken,
                                                                               string key,
                                                                               PutExtra extra)
        {
            //System.Collections.Specialized
            WebHeaderCollection webHeader = new WebHeaderCollection
            {
                ["token"] = upToken
            };

            //NameValueCollection formData = new NameValueCollection();
            //formData["token"] = upToken;

            if (key != null)
            {
                webHeader["key"] = key;
                //formData["key"] = key;
            }
            if (extra != null)
            {
                if (extra.CheckCrc == CheckCrcType.CHECK_AUTO)
                {
                    webHeader["crc32"] = extra.Crc32.ToString();
                    //formData["crc32"] = extra.Crc32.ToString();
                }
                if (extra.Params != null)
                {
                    foreach (KeyValuePair <string, string> pair in extra.Params)
                    {
                        webHeader[pair.Key] = pair.Value;
                        //formData[pair.Key] = pair.Value;
                    }
                }
            }
            return(webHeader);
            //return formData;
        }
Beispiel #2
0
        /// <summary>
        ///     上传文件
        /// </summary>
        /// <param name="upToken"></param>
        /// <param name="key"></param>
        /// h
        /// <param name="localFile"></param>
        /// <param name="extra"></param>
        private async Task <PutRet> PutFile(string upToken, string key, string localFile, PutExtra extra)
        {
            if (!File.Exists(localFile))
            {
                throw new Exception(string.Format("{0} does not exist", localFile));
            }
            //PutRet ret;

            /*NameValueCollection*/
            WebHeaderCollection formData = GetFormData(upToken, key, extra);

            try
            {
                CallRet callRet = await MultiPart.MultiPost(Config.UP_HOST, formData, localFile, this.Proxy);

                var ret = new PutRet(callRet);
                PutFinished(ret);
                return(ret);
            }
            catch (Exception e)
            {
                var ret = new PutRet(new CallRet(HttpStatusCode.BadRequest, e));
                PutFinished(ret);
                return(ret);
            }
        }
Beispiel #3
0
        /// <summary>
        /// </summary>
        /// <param name="upToken">Up token.</param>
        /// <param name="key">Key.</param>
        /// <param name="putStream">Put stream.</param>
        /// <param name="extra">Extra.</param>
        private async Task <PutRet> Put(string upToken, string key, Stream putStream, PutExtra extra)
        {
            if (!putStream.CanRead)
            {
                throw new Exception("read put Stream error");
            }
            //PutRet ret;
            /*NameValueCollection*/
            WebHeaderCollection formData = GetFormData(upToken, key, extra);

            try
            {
                CallRet callRet = await MultiPart.MultiPost(Config.UP_HOST, formData, putStream);

                var ret = new PutRet(callRet);
                PutFinished(ret);
                return(ret);
            }
            catch (Exception e)
            {
                var ret = new PutRet(new CallRet(HttpStatusCode.BadRequest, e));
                PutFinished(ret);
                return(ret);
            }
        }
Beispiel #4
0
 /// <summary>
 ///     Puts the file without key.
 /// </summary>
 /// <returns>The file without key.</returns>
 /// <param name="upToken">Up token.</param>
 /// <param name="localFile">Local file.</param>
 /// <param name="extra">Extra.</param>
 private async Task <PutRet> PutFileWithoutKey(string upToken, string localFile, PutExtra extra)
 {
     return(await PutFile(upToken, null, localFile, extra));
 }