public void can_upload_file() { string filePath = Directory.GetCurrentDirectory() + @"\test.xml"; File.WriteAllText(filePath, "test"); var aot = new AliyunOSSTransfer(OssEndPoint, AccessKeyId, AccessKeySecret); var aos = new AliyunOssSource(aot, BucketName, SourceRoot); string OssTestXml = SourceRoot + "/test.xml"; aot.DeleteObject(BucketName, OssTestXml); Assert.AreEqual(aot.GetObjectSize(BucketName, OssTestXml), 0); Assert.IsTrue(aos.DeployData("test.xml", "", null, filePath)); Assert.AreEqual(aot.GetObjectSize(BucketName, OssTestXml), new FileInfo(filePath).Length); aot.DeleteObject(BucketName, OssTestXml); File.Delete(filePath); }
private void btnUploadFiles_Click(object sender, EventArgs e) { try { if (_serverProfile == null) { MessageBox.Show("���ȼ��ط���������!"); return; } //�����ʱĿ¼ if (Directory.Exists(_uploadTempDirectory)) { Directory.Delete(_uploadTempDirectory, true); } var aot = new AliyunOSSTransfer(_serverProfile.OssEndPoint , _serverProfile.OssAccessKeyID, _serverProfile.OssAccessKeySecret); var aos = new AliyunOssSource(aot, _serverProfile.OssBucketName, _serverProfile.OssSourceRoot); int uploadProgressSubItemIndex = 5; //���ź���C#��bug��û�а취����ColumnName�������� foreach (ListViewItem thisItem in lstFiles.Items) { //������ϴε��ϴ���־ thisItem.SubItems[uploadProgressSubItemIndex].Text = "-.-"; //û��ѡ�е��ļ����ϴ� if (!thisItem.Checked) { thisItem.SubItems[uploadProgressSubItemIndex].Text = "���ϴ�"; continue; } //���̸߳���listView������ Action<string> notifySubitemProgressText = (notifyText) => { lstFiles.BeginInvoke((MethodInvoker)delegate () { thisItem.SubItems[uploadProgressSubItemIndex].Text = notifyText; }); }; //���½��� Action<UpdateProgressInfo> onProgress = (updateProgressInfo) => { notifySubitemProgressText(string.Format("{0}%", updateProgressInfo.Percentage)); }; FileInfoEx fileInfo = (FileInfoEx)thisItem.Tag; //���ļ���������ʱ�ļ������棬����Ҫ�ϴ����ļ���ռ�� Directory.CreateDirectory(_uploadTempDirectory); string tempFilePath = _uploadTempDirectory + fileInfo.FileInfo.Name; File.Copy(fileInfo.FileInfo.FullName, tempFilePath, true); //�߳��ϴ����������ܼ�ʱ���½��� Thread uploadThread = new Thread(delegate () { if (aos.DeployData(fileInfo.FileInfo.Name, "", onProgress, tempFilePath) == false) { notifySubitemProgressText("ʧ��"); } }); uploadThread.Start(); } } catch (Exception ex) { MessageBox.Show(string.Format("�ϴ��ļ�����:%s", ex.Message)); } }