开发者社区> 问答> 正文

OSS进度条

下载了.net SDK,和OssSamples,

public static void PutObjectProgress(string bucketName,FileInfo finfo)
    {
        const string key = "PutObjectProgress";
        try
        {
            using (var fs = File.Open(finfo.Directory.ToString(), FileMode.Open))
            {
                var putObjectRequest = new PutObjectRequest(bucketName, key, fs);
                putObjectRequest.StreamTransferProgress += streamProgressCallback;

                client.PutObject(putObjectRequest);
            }
            Console.WriteLine("Put object:{0} succeeded", key);
        }
        catch (OssException ex)
        {
            Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Failed with error info: {0}", ex.Message);
        }
    }

    private  static void streamProgressCallback(object sender, StreamTransferProgressArgs args)
    {

        System.Console.WriteLine("ProgressCallback - TotalBytes:{0}, TransferredBytes:{1}",
            args.TotalBytes, args.TransferredBytes);           
    }
    private void button1_Click(object sender, EventArgs e)
    {
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            string fName = openFileDialog1.FileName;
            FileInfo fileInf = new FileInfo(fName);
            PutObjectProgress(bucketName, fileInf);
            SimpleListObjects(bucketName);
        }

    }

1.如何 在winform 显示进度,streamProgressCallback方法是静态的,无法访问 winform form中 控件

  1. using (var fs = File.Open(finfo.Directory.ToString(), FileMode.Open)) 提示访问被拒绝

展开
收起
gy348 2017-06-24 14:34:48 4890 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载