コード例 #1
0
        /// <summary>
        /// 根据文件字节数组上传
        /// </summary>
        /// <param name="param">文件流上传配置</param>
        /// <param name="isResume">是否允许续传</param>
        /// <returns></returns>
        public UploadResultDto UploadByteArray(UploadByByteArrayParam param, bool isResume = false)
        {
            return(ToolCommon.GetResponse(() =>
            {
                var zone = Core.Tools.GetZone(_aLiYunConfig, param.UploadPersistentOps.Zone,
                                              () => ZoneEnum.HangZhou);
                var client = _aLiYunConfig.GetClient(zone);
                return Upload(isResume, (bucket, newPersistentOps, objectMetadata) =>
                {
                    PutObjectResult ret;
                    if (isResume)
                    {
                        var request = new UploadObjectRequest(bucket, param.Key, param.ByteArray.ConvertToStream())
                        {
                            PartSize = Core.Tools.GetPartSize(
                                Core.Tools.GetChunkUnit(_aLiYunConfig, newPersistentOps.ChunkUnit,
                                                        () => ChunkUnit.U2048K)),
                            Metadata = objectMetadata
                        };
                        ret = client.ResumableUploadObject(request);
                    }
                    else
                    {
                        ret = client.PutObject(bucket, param.Key, param.ByteArray.ConvertToStream(), objectMetadata);
                    }

                    return ret;
                }, param.UploadPersistentOps);
            }, (message, ex) => new UploadResultDto(false, ex, message)));
        }
コード例 #2
0
        /// <summary>
        /// 根据文件字节数组上传
        /// </summary>
        /// <param name="param">文件流上传配置</param>
        /// <param name="isResume">是否允许续传(续传采用非表单提交方式)</param>
        /// <returns></returns>
        public UploadResultDto UploadByteArray(UploadByByteArrayParam param, bool isResume = false)
        {
            var    uploadPersistentOps = GetUploadPersistentOps(param.UploadPersistentOps);
            string token = GetUploadCredentials(QiNiuConfig,
                                                new UploadPersistentOpsParam(param.Key, uploadPersistentOps));

            if (isResume)
            {
                ResumableUploader target =
                    new ResumableUploader(Core.Tools.GetConfig(QiNiuConfig, uploadPersistentOps));
                HttpResult result =
                    target.UploadStream(param.ByteArray.ConvertToStream(), param.Key, token,
                                        GetPutExtra(uploadPersistentOps));
                bool res = result.Code == (int)HttpCode.OK;
                return(new UploadResultDto(res, result, res ? "成功" : result.ToString()));
            }
            else
            {
                FormUploader target = new FormUploader(Core.Tools.GetConfig(QiNiuConfig, uploadPersistentOps));
                HttpResult   result =
                    target.UploadData(param.ByteArray, param.Key, token, GetPutExtra(uploadPersistentOps));
                bool res = result.Code == (int)HttpCode.OK;
                return(new UploadResultDto(res, result, res ? "成功" : result.ToString()));
            }
        }
コード例 #3
0
        /// <summary>
        /// 根据文件字节数组上传
        /// </summary>
        /// <param name="param">文件流上传配置</param>
        /// <returns></returns>
        public UploadResultDto UploadByteArray(UploadByByteArrayParam param)
        {
            var    uploadPersistentOps = GetUploadPersistentOps(param.UploadPersistentOps);
            string token = GetUploadCredentials(QiNiuConfig,
                                                new UploadPersistentOpsParam(param.Key, uploadPersistentOps));
            FormUploader target = new FormUploader(GetConfig(uploadPersistentOps));
            HttpResult   result =
                target.UploadData(param.ByteArray, param.Key, token, GetPutExtra(uploadPersistentOps));
            bool res = result.Code == (int)HttpCode.OK;

            return(new UploadResultDto(res, res ? "成功" : result.ToString()));
        }
コード例 #4
0
        /// <summary>
        /// 根据文件字节数组上传
        /// </summary>
        /// <param name="param">文件流上传配置</param>
        /// <param name="isResume">是否允许续传</param>
        /// <returns></returns>
        public UploadResultDto UploadByteArray(UploadByByteArrayParam param, bool isResume = false)
        {
            var res = base.UploadFile(param.ByteArray.ConvertToStream(), param.Key, Path.GetExtension(param.Key));

            return(new UploadResultDto(res, "", res ? "上传成功" : "上传失败"));
        }