Exemplo n.º 1
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="upToken"></param>
        /// <param name="key"></param>h
        /// <param name="localFile"></param>
        /// <param name="extra"></param>
        public async Task <PutRet> PutFileAsync(string upToken, string key, string localFile, PutExtra extra)
        {
            if (!System.IO.File.Exists(localFile))
            {
                throw new Exception(string.Format("{0} does not exist", localFile));
            }
            PutRet ret;

            NameValueCollection formData = getFormData(upToken, key, extra);

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

                ret = new PutRet(callRet);
                onPutFinished(ret);
                return(ret);
            }
            catch (Exception e)
            {
                ret = new PutRet(new CallRet(HttpStatusCode.BadRequest, e));
                onPutFinished(ret);
                return(ret);
            }
        }
Exemplo n.º 2
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 PutRet Put(string upToken, string key, System.IO.Stream putStream, PutExtra extra)
        {
            if (!putStream.CanRead)
            {
                throw new Exception("read put Stream error");
            }
            PutRet ret;
            NameValueCollection formData = getFormData(upToken, key, extra);

            try
            {
                CallRet callRet = MultiPart.MultiPost(Config.UP_HOST, formData, putStream);
                ret = new PutRet(callRet);
                onPutFinished(ret);
                return(ret);
            }
            catch (Exception e)
            {
                ret = new PutRet(new CallRet(HttpStatusCode.BadRequest, e));
                onPutFinished(ret);
                return(ret);
            }
        }