开发者社区> 问答> 正文

通过代理上传文件异常 求助


//1.为Ossclient设置代理
ClientConfiguration cfg = new ClientConfiguration();
                cfg.ProxyHost = proxyHost;
                cfg.ProxyPort = proxyPort;
                cfg.ProxyUserName = proxyUserName;
                cfg.ProxyPassword = proxyPassword;
                cfg.MaxErrorRetry = 3;
                cfg.ConnectionTimeout = 5000;
                _Client = new OssClient(new Uri(endPoint), accessKeyId, accessKeySecret, cfg);
//2.上传文件代码

using (var fs = File.Open(zipFile.FullName, FileMode.Open))
{
         var metadata = new ObjectMetadata();
         metadata.ContentLength = fs.Length;
         metadata.UserMetadata.Add("company", "1234");


         _Client.PutObject(_bucketName, fileFoler, fs, metadata);
   }
//3.报异常
{"在写入所有字节之前不能关闭流。"}

在 System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
   在 System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
   在 System.Net.ConnectStream.Dispose(Boolean disposing)
   在 System.IO.Stream.Close()
   在 System.IO.Stream.Dispose()
   在 Aliyun.OpenServices.Common.Communication.ServiceClientImpl.SetRequestContent(HttpWebRequest webRequest, ServiceRequest serviceRequest, Boolean async, Action asyncCallback)
   在 Aliyun.OpenServices.Common.Communication.ServiceClientImpl.SendCore(ServiceRequest serviceRequest, ExecutionContext context)
   在 Aliyun.OpenServices.Common.Communication.ServiceClient.Send(ServiceRequest request, ExecutionContext context)
   在 Aliyun.OpenServices.Common.Communication.RetryableServiceClient.SendImpl(ServiceRequest request, ExecutionContext context, Int32 retries)
   在 Aliyun.OpenServices.Common.Communication.RetryableServiceClient.Send(ServiceRequest request, ExecutionContext context)
   在 Aliyun.OpenServices.OpenStorageService.Commands.OssCommand.Execute()
   在 Aliyun.OpenServices.OpenStorageService.Commands.OssCommand`1.Execute()
   在 Aliyun.OpenServices.OpenStorageService.OssClient.PutObject(String bucketName, String key, Stream content, ObjectMetadata metadata)
   在 SensitiveDetectorHost.AliOSS.PutObject(String fileFoler, FileStream fs, ObjectMetadata metadata) 位置 d:\Project\FIP\trunk\VideoLocalHost\SensitiveDetectorHost\AliOSS\AliOSS.cs:行号 151

展开
收起
xtaqukq 2015-12-29 15:10:06 5421 0
3 条回答
写回答
取消 提交回答
  • Re通过代理上传文件异常 求助
    不使用代理是不是没问题?
    如果不使用代理没问题,那有可能是代理和oss之间的链接提前超时断开了。检查本地直连oss的超时时间和使用代理的时候的超时时间是否一致。
    2015-12-30 11:42:58
    赞同 展开评论 打赏
  • Re通过代理上传文件异常 求助
    效果一样的,我把Using去掉了,不关闭文件流也报这个异常;
    还试过PutObject直接传入文件路径的那个接口,也是这个异常;
    我的Aliyun.OSS.dll版本是1.1,用官方提供的2.2版本,加代理也试过了。
    2015-12-29 15:19:21
    赞同 展开评论 打赏
  • using (var fs = File.Open(zipFile.FullName, FileMode.Open))
    不要用using试试
    2015-12-29 15:12:29
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载