bluetianx / BirdMessenger

DotNET client implementation of the Tus protocol for resumable file uploads.
https://tus.io/
MIT License
63 stars 12 forks source link

v2.2.0,在 tusClient.Create(....)时程序直接退出,没有任何错误提示 #40

Closed ghost closed 2 years ago

bluetianx commented 2 years ago

有可以重现的代码示例吗

ghost commented 2 years ago

核心代码:

`if (_tusClient == null) { // 远程 tus 服务 Uri hostUri = new Uri(this.Url);

                // 创建标准 tus 客户端实例
                _tusClient = TusBuild.DefaultTusClientBuild(hostUri)
                    .Configure((options, httpClientBuilder) =>
                    {
                        // 自定义 tus 上传色织
                        options.TusHost = hostUri;
                        options.GetChunkUploadSize = (src, ctx) => 1024 * 1024 * 10;   // 10Mb per-chunk
                        options.FileNameMetadataName = "meta_filename";

                        // 自定义 http 客户端
                        httpClientBuilder.ConfigureHttpClient(httpClient =>
                            {
                                //httpClient.DefaultRequestHeaders.Authorization =
                                //    new AuthenticationHeaderValue("Bearer", "ACCESS_TOKEN");
                            });
                        httpClientBuilder.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()
                        {
                            UseCookies = false,
                        });
                    })
                    .Build();

                // 订阅事件
                _tusClient.UploadProgress += TusClient_UploadProgress;
                _tusClient.UploadFinish += TusClient_UploadFinish;
            }`

`FileInfo uploadFile = new FileInfo(this.FileFullName);

            // 自定义附加的请求元数据 
            MetadataCollection metadatas = new MetadataCollection();
            metadatas["RelativePath"] = this.RelativePath;
            metadatas["FileTypeCode"] = this.FileTypeCode;
            metadatas["FileSize"] = uploadFile.Length.ToString();
            metadatas["ClientName"] = System.Net.Dns.GetHostName();
            metadatas["Md5"] = this.FileMd5;
            metadatas["LastWriteTime"] = uploadFile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");

            // 定义 tus 请求相关设置
            TusRequestOption requestOption = new TusRequestOption();
            //requestOption.HttpHeader["myHttpheader"] = "hello";

            // tus 上传地址
            Uri uploadUrl = null;

            var rec = LocalUploadRecorder.Instance.GetRecord(this.FileMd5);
            // 续传
            if (rec != null)
            {
                uploadUrl = new Uri(rec.Url);
            }
            // 新上传
            else
            {
                uploadUrl = await _tusClient.Create(uploadFile, metadatas, requestOption, _cancellationTokenSource.Token);

...`

你好,开发者,这是我的代码

bluetianx commented 2 years ago

你用try catch 抓取一下异常,估计是抛出异常了

ghost commented 2 years ago

我外面有try catch,也没有异常,程序直接退出了

ghost commented 2 years ago

image

bluetianx commented 2 years ago

运行项目的demo 示例 可以吗

ghost commented 2 years ago

我试试

bluetianx commented 2 years ago

https://github.com/bluetianx/BirdMessenger/blob/master/samples/demo/Program.cs

ghost commented 2 years ago

请问一下作者,要是没上传完关了程序,想断点续传,只要使用上次的 uploadUrl,就能续传是么?

ghost commented 2 years ago

image 这个是正常的。奥,我的Uri是https的,是这个问题么?不支持 https 嘛?

ghost commented 2 years ago

哎,还是一点错误提示也没有

bluetianx commented 2 years ago

请问一下作者,要是没上传完关了程序,想断点续传,只要使用上次的 uploadUrl,就能续传是么?

是的

bluetianx commented 2 years ago

哎,还是一点错误提示也没有

应该是有异常抛出的,Https 会重现你的问题?

ghost commented 2 years ago

没有,情况一样,没有任何错误信息,也没有异常,我的控制台程序直接退出了

ghost commented 2 years ago

哈哈...我知道什么原因了... 低级错误,外面的方法应该用 await..................... 遗漏了

ghost commented 2 years ago

谢谢你这么耐心

bluetianx commented 2 years ago

没事,欢迎star