コード例 #1
0
ファイル: BackblazeB2Adapter.cs プロジェクト: yvanam/SyncPro
        /// <summary>
        /// Get a stream for writing the contents of an item
        /// </summary>
        /// <param name="entry">The entry representing the file to be uploaded</param>
        /// <param name="length">The length of the file to be uploaded</param>
        /// <returns>The <see cref="Stream"/>that the file's content can be written to</returns>
        public override Stream GetWriteStreamForEntry(SyncEntry entry, long length)
        {
            // Create a default session. By itself, the file will be uploaded to Backblaze when the stream
            // containins the session is disposed.
            BackblazeB2UploadSession session = new BackblazeB2UploadSession(entry, length);

            // If the file is large enough, call the method below to get the large file upload information. When
            // these properties are present, the stream will upload the file's parts individually.
            if (length >= this.TypedConfiguration.ConnectionInfo.RecommendedPartSize)
            {
                session.StartLargeFileResponse =
                    this.backblazeClient.StartLargeUpload(
                        this.TypedConfiguration.BucketId,
                        entry.GetRelativePath(null, "/"))
                    .Result;

                session.GetUploadPartUrlResponse =
                    this.backblazeClient.GetUploadPartUrl(session.StartLargeFileResponse.FileId).Result;

                // Return the stream type dedicated to uploading large files (via parts)
                return(new BackblazeB2LargeUploadStream(
                           this,
                           session,
                           Constants.LimitPartMaximumSize,
                           length));
            }

            // The file size is below the large-file limit, so upload directly
            return(new BackblazeB2UploadStream(this, session));
        }
コード例 #2
0
        public BackblazeB2UploadStream(
            BackblazeB2Adapter adapter,
            BackblazeB2UploadSession session)
        {
            this.adapter = adapter;
            this.Session = session;

            this.memoryStream = new MemoryStream();
        }
コード例 #3
0
 public BackblazeB2LargeUploadStream(
     BackblazeB2Adapter adapter,
     BackblazeB2UploadSession session,
     long partSize,
     long fileSize)
     : base(partSize, fileSize)
 {
     this.adapter = adapter;
     this.Session = session;
 }
コード例 #4
0
ファイル: BackblazeB2Adapter.cs プロジェクト: yvanam/SyncPro
 public async Task <UploadPartResponse> UploadPart(
     BackblazeB2UploadSession session,
     int partNumber,
     string sha1Hash,
     long size,
     Stream contentStream)
 {
     return(await this.backblazeClient.UploadPart(
                session.GetUploadPartUrlResponse.UploadUrl,
                session.GetUploadPartUrlResponse.AuthorizationToken,
                partNumber,
                sha1Hash,
                size,
                contentStream)
            .ConfigureAwait(false));
 }