如何使用.NET客户端库从上传URI恢复到GCS的上传?

时间:2018-09-24 15:34:09

标签: google-cloud-platform google-cloud-storage

只需尝试恢复已中断的上传(已收到其上传URI)作为对InsertMediaUpload的 InitiateSessionAsync 方法的响应即可。但是ResumableUpload。 CreateFromUploadUri ()调用不会从中断的地方继续上传。

            if (File.Exists(URIFile))
            {
                if (Uri.TryCreate(File.ReadAllText(URIFile), UriKind.Absolute, out uploadURI))
                {
                    var credential = GoogleCredential.FromFile(adcPath);

                    var storage = StorageClient.Create(credential);

                    var filestream = new FileStream(filepath, FileMode.Open, FileAccess.Read);

                    if (filestream.CanSeek)
                    {
                        var ResumableUploadFromURI = ResumableUpload.CreateFromUploadUri(uploadURI, filestream, new ResumableUploadOptions()
                        {
                            ServiceName = "GcsSample"
                        });

                        progressBar1.Maximum = (int)filestream.Length;

                        ResumableUploadFromURI.ChunkSize = 262144;

                        ResumableUploadFromURI.ProgressChanged += OnUploadProgress;

                        ResumableUploadFromURI.ResumeAsync();
                    }
                }
            } 

0 个答案:

没有答案