Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeginPutObject函数的文件流释放造成异步请求报错 #33

Open
vla opened this issue Sep 27, 2017 · 3 comments
Open

BeginPutObject函数的文件流释放造成异步请求报错 #33

vla opened this issue Sep 27, 2017 · 3 comments

Comments

@vla
Copy link

vla commented Sep 27, 2017

  public IAsyncResult BeginPutObject(string bucketName, string key, string fileToUpload, ObjectMetadata metadata,
            AsyncCallback callback, object state)
        {
            if (!File.Exists(fileToUpload) || Directory.Exists(fileToUpload))
                throw new ArgumentException(String.Format("Invalid file path {0}.", fileToUpload));

            metadata = metadata ?? new ObjectMetadata();
            SetContentTypeIfNull(key, fileToUpload, ref metadata);

            IAsyncResult result;
            //TODO 这里释放了content导致ServiceClientImpl报错
            using (Stream content = File.OpenRead(fileToUpload))
            {
                result = BeginPutObject(bucketName, key, content, metadata, callback, state);
            }
            return result;
        }

ServiceClientImpl报错位置

  if (async)
            {
                webRequest.BeginGetRequestStream(
                    (ar) =>
                    {
                        using (var requestStream = webRequest.EndGetRequestStream(ar))
                        {
                            //TODO data已被释放
                            IoUtils.WriteTo(data, requestStream, webRequest.ContentLength);
                        }
                        asyncCallback();
                    }, null);
            }
@nishizhen
Copy link

和我报的是一个吧? #32

@vla
Copy link
Author

vla commented Sep 30, 2017

@nishizhen 不是,这个是他的BUG!这里处理太慢了,我自己fork了发布了一个到NUGET去用了

@zousq19910623
Copy link

请教一下,怎么修复的。
我现在使用多线程去GetObjects也出现了报错
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants