internal B2File(B2Client b2Client, B2FileInfo file) { _b2Client = b2Client; _file = file; State = B2FileState.Present; }
internal B2File(B2Client b2Client, string bucketId, string newName) { _b2Client = b2Client; _file = new B2FileInfo { Action = B2FileAction.Upload, FileName = newName, BucketId = bucketId, ContentType = B2Constants.AutoContenType }; State = B2FileState.New; }
internal B2LargeFile(B2Client b2Client, B2FileInfo file) { _file = new B2UnfinishedLargeFile { AccountId = file.AccountId, BucketId = file.BucketId, FileName = file.FileName, ContentType = file.ContentType, FileId = file.FileId, FileInfo = file.FileInfo, UploadTimestamp = file.UploadTimestamp }; _b2Client = b2Client; State = B2LargeFileState.New; }
public async Task<B2File> UploadFileDataAsync(FileInfo file) { ThrowIfNot(B2FileState.New); B2UploadConfiguration config = _b2Client.FetchUploadConfig(BucketId); try { using (var fs = file.OpenRead()) { string sha1Hash; using (SHA1 sha1 = SHA1.Create()) sha1Hash = BitConverter.ToString(sha1.ComputeHash(fs)).Replace("-", ""); fs.Seek(0, SeekOrigin.Begin); B2FileInfo result = await _b2Client.Communicator.UploadFile(config.UploadUrl, config.AuthorizationToken, fs, sha1Hash, FileName, ContentType, FileInfo, _uploadNotifyDelegate); if (result.ContentSha1 != sha1Hash) throw new ArgumentException("Bad transfer - hash mismatch"); _file = result; } State = B2FileState.Present; } finally { _b2Client.ReturnUploadConfig(config); } return this; }
public async Task<B2File> RefreshAsync() { B2FileInfo info = await _b2Client.Communicator.GetFileInfo(FileId); _file = info; return this; }
public async Task<B2File> UploadDataAsync(Stream source) { ThrowIfNot(B2FileState.New); B2UploadConfiguration config = _b2Client.FetchUploadConfig(BucketId); try { B2FileInfo result = await _b2Client.Communicator.UploadFile(config.UploadUrl, config.AuthorizationToken, source, ContentSha1, FileName, ContentType, FileInfo, _uploadNotifyDelegate); if (result.ContentSha1 != ContentSha1) throw new ArgumentException("Bad transfer - hash mismatch"); _file = result; State = B2FileState.Present; } finally { _b2Client.ReturnUploadConfig(config); } return this; }