Ejemplo n.º 1
0
        /**
         * 开始上传,新建一个线程用于IO操作
         */
        private void start()
        {
            PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucketName, this.file.Name, this.file);
            putObjectRequest.setProgressListener(this);

            Thread thread = new Thread(delegate() {
                try
                {
                    ks3Client.putObject(putObjectRequest);
                }
                catch (ServiceException e)
                {
                    showMessage(e.ToString(), "错误");
                }
                catch (ProgressInterruptedException e)
                {
                    // Do nothing here ...
                }
                catch
                {
                    showMessage("未知错误,请稍后再试", "错误");
                }

            });
            thread.Start();
        }
Ejemplo n.º 2
0
        private static bool putObject()
        {
            try
            {
                // Put Object(upload a short content)
                Console.WriteLine("--- Upload a Short Content: ---");

                String sampleContent = "This is a sample content.(25 characters before, included the 4 spaces)";
                Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(sampleContent));
                PutObjectResult shortContentResult = ks3Client.putObject(bucketName, objKeyNameMemoryData, stream, null);

                Console.WriteLine("Upload Completed. eTag=" + shortContentResult.getETag() + ", MD5=" + shortContentResult.getContentMD5());
                Console.WriteLine("-------------------------------\n");

                // Put Object(upload a file)
                Console.WriteLine("--- Upload a File ---");

                FileInfo file = new FileInfo(inFilePath);
                PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objKeyNameFileData, file);
                SampleListener sampleListener = new SampleListener(file.Length);
                putObjectRequest.setProgressListener(sampleListener);
                PutObjectResult putObjectResult = ks3Client.putObject(putObjectRequest);

                Console.WriteLine("Upload Completed. eTag=" + putObjectResult.getETag() + ", MD5=" + putObjectResult.getContentMD5());
                Console.WriteLine("---------------------\n");
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.ToString());
                return false;
            }

            return true;
        }