Exemplo n.º 1
0
        /// <summary>
        ///     上传文件数据流,根据文件大小以及设置的阈值(用户初始化UploadManager时可指定该值)自动选择:
        ///     若文件大小超过设定阈值,使用ResumableUploader,否则使用FormUploader
        /// </summary>
        /// <param name="stream">待上传的数据流</param>
        /// <param name="key">要保存的文件名称</param>
        /// <param name="token">上传凭证</param>
        /// <param name="extra">上传可选设置</param>
        /// <returns>上传文件后的返回结果</returns>
        public Task <HttpResult> UploadStream(Stream stream, string key, string token, PutExtra extra)
        {
            if (stream.Length > _config.PutThreshold)
            {
                var resumeUploader = new ResumableUploader(_config);
                return(resumeUploader.UploadStream(stream, key, token, extra));
            }

            var formUploader = new FormUploader(_config);

            return(formUploader.UploadStream(stream, key, token, extra));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 上传文件数据流,根据文件大小以及设置的阈值(用户初始化UploadManager时可指定该值)自动选择:
        /// 若文件大小超过设定阈值,使用ResumableUploader,否则使用FormUploader
        /// </summary>
        /// <param name="stream">待上传的数据流</param>
        /// <param name="key">要保存的文件名称</param>
        /// <param name="token">上传凭证</param>
        /// <param name="extra">上传可选设置</param>
        /// <returns>上传文件后的返回结果</returns>
        public HttpResult UploadStream(Stream stream, string key, string token, PutExtra extra)
        {
            HttpResult result = new HttpResult();

            if (stream.Length > this.config.PutThreshold)
            {
                ResumableUploader resumeUploader = new ResumableUploader(this.config);
                result = resumeUploader.UploadStream(stream, key, token, extra);
            }
            else
            {
                FormUploader formUploader = new FormUploader(this.config);
                result = formUploader.UploadStream(stream, key, token, extra);
            }

            return(result);
        }