Esempio n. 1
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. 2
0
        public ObjectMetadata GetObject(AliyunDownloadRequst downloadRequst)
        {
            ObjectMetadata ret = null;
            using (FileStream fs = new FileStream(downloadRequst.file, FileMode.Create))
            {
                long totalBytes = GetObjectSize(downloadRequst.bucketName, downloadRequst.key);
                AliyunStream stream = new AliyunStream(fs);
                stream.WritePositionChangeEvent += delegate(long nowPosition, long _totalBytes)
                {
                    downloadRequst.TransferFile(nowPosition, totalBytes);
                };
                GetObjectRequest getObjectRequest = new GetObjectRequest(downloadRequst.bucketName, downloadRequst.key);
                ret = _ossClient.GetObject(getObjectRequest, stream);
            }

            return ret;
        }