Esempio n. 1
0
 public bool DeployData(string fileKey, string baseKey, Action<UpdateProgressInfo> onProgress, string fileLocation)
 {
     try
     {
         //aliyun对于"a//b"这样的路径不认,只认"a/b"
         string fullFileKey = (SourceRoot + "/" + baseKey + "/" + fileKey).Replace("//", "/");
         AliyunUploadRequest uploadRequest = new AliyunUploadRequest(BucketName, fullFileKey
             , fileLocation);
         uploadRequest.TranseferFileEvent += delegate (long transferedBytes, long totalBytes)
         {
             onProgress(new UpdateProgressInfo
             {
                 Percentage = (totalBytes == 0) ? 0 : (int)(transferedBytes * 100 / totalBytes),
                 StillWorking = (transferedBytes != totalBytes),
             });
         };
         AliyunTransfer.PutObejct(uploadRequest);
         return true;
     }
     catch (Exception ex)
     {
         string a = ex.ToString();
     }
     return false;
 }
Esempio n. 2
0
        public PutObjectResult PutObejct(AliyunUploadRequest uploadRequest)
        {
            var fileHash = NAppUpdate.Framework.Utils.FileChecksum.GetSHA256Checksum(uploadRequest.file);
            //网上的文件是正确的了,不上传了,相当于文件级别的断点续传
            if (GetObjectEtag(uploadRequest.bucketName, uploadRequest.key).ToUpper()
                 == fileHash)
            {
                return null;
            }

            PutObjectResult ret = null;
            using (FileStream fs = new FileStream(uploadRequest.file, FileMode.Open))
            {
                AliyunStream stream = new AliyunStream(fs);
                stream.ReadPositionChangeEvent += delegate(long nowPosition, long totalBytes)
                {
                    uploadRequest.TransferFile(nowPosition, totalBytes);
                };
                ret = _ossClient.PutObject
                    (
                    uploadRequest.bucketName, uploadRequest.key, stream,
                    new ObjectMetadata()
                    {
                        ContentLength = fs.Length,
                        ETag = fileHash,                                    //ETag记录SHA256值,用于短点续传的判断
                    }
                    );
            }

            return ret;
        }
Esempio n. 3
0
        /// <summary>
        /// 目录上传,只支持一层目录
        /// </summary>
        /// <param name="uploadDirectoryRequest"></param>
        public void PutDirectory(AliyunUploadDirectoryRequest uploadDirectoryRequest)
        {
            if (Directory.Exists(uploadDirectoryRequest.directory) == false)
            {
                throw new DirectoryNotFoundException();
            }

            DirectoryInfo dirInfo = new DirectoryInfo(uploadDirectoryRequest.directory);
            FileInfo[] files = dirInfo.GetFiles();
            int totalFiles = files.Length;
            int transferFiles = 0;
            foreach (var file in files)
            {
                AliyunUploadRequest uploadRequest = new AliyunUploadRequest(uploadDirectoryRequest.bucketName,
                    uploadDirectoryRequest.key + @file.Name, file.FullName);
                uploadRequest.TranseferFileEvent += delegate(long transferedBytes, long totalBytes)
                {
                    uploadDirectoryRequest.TransferDirectory(transferedBytes, totalBytes, transferFiles, totalFiles);
                };

                PutObejct(uploadRequest);
                transferFiles++;
            }
        }