Esempio n. 1
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>
        public 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);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     上传文件
        /// </summary>
        /// <param name="upToken"></param>
        /// <param name="key"></param>
        /// h
        /// <param name="localFile"></param>
        /// <param name="extra"></param>
        public 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);
            }
        }