Beispiel #1
0
 protected void onPutFinished(PutRet ret)
 {
     if (PutFinished != null)
     {
         PutFinished(this, ret);
     }
 }
Beispiel #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;
     }
 }
Beispiel #3
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="upToken"></param>
        /// <param name="key"></param>h
        /// <param name="localFile"></param>
        /// <param name="extra"></param>
        public PutRet PutFile(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 = MultiPart.MultiPost(Config.UP_HOST, formData, localFile);
                ret = new PutRet(callRet);
                onPutFinished(ret);
                return ret;
            }
            catch (Exception e)
            {
                ret = new PutRet(new CallRet(HttpStatusCode.BadRequest, e));
                onPutFinished(ret);
                return ret;
            }
        }
        /// <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);
            }
        }
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="upToken"></param>
        /// <param name="key"></param>h
        /// <param name="localFile"></param>
        /// <param name="extra"></param>
        public PutRet PutFile(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 = MultiPart.MultiPost(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);
            }
        }
Beispiel #6
0
 protected void onPutFinished(PutRet ret)
 {
     if (PutFinished != null)
     {
         PutFinished(this, ret);
     }
 }
Beispiel #7
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="key">文件名称</param>
        /// <param name="fname">本地文件名称</param>
        /// <param name="rewrite">是否覆盖</param>
        private void PutFile(string key, string fname, bool rewrite = false)
        {
            string scope = mBucket;
            if (rewrite)
                scope += ":" + key;

            string upToken = new PutPolicy(scope).Token();
            IOClient client = new IOClient();
            client.PutFinished += (o, ret) =>
            {
                mPutRet = ret;
                mIsDonePut = true;
            };
            client.PutFile(upToken, key, fname, null);
        }