示例#1
0
 /// <summary>
 /// Creates a copy of an object synchronously, potentially to a different bucket. This method uses the
 /// <c>rewriteObject</c> underlying API operation for more flexibility and reliability.
 /// </summary>
 /// <param name="sourceBucket">The name of the bucket containing the object to copy. Must not be null.</param>
 /// <param name="sourceObjectName">The name of the object to copy within the bucket. Must not be null.</param>
 /// <param name="destinationBucket">The name of the bucket to copy the object to. Must not be null.</param>
 /// <param name="destinationObjectName">The name of the object within the destination bucket. Must not be null.</param>
 /// <param name="options">Additional options for the fetch operation. May be null, in which case appropriate
 /// defaults will be used.</param>
 /// <exception cref="ArgumentException">The arguments attempt to copy an object to itself.</exception>
 /// <returns>The <see cref="Object"/> representation of the new storage object resulting from the copy.</returns>
 public virtual Object CopyObject(
     string sourceBucket,
     string sourceObjectName,
     string destinationBucket,
     string destinationObjectName,
     CopyObjectOptions options = null)
 {
     throw new NotImplementedException();
 }
示例#2
0
 /// <summary>
 /// Creates a copy of an object synchronously, potentially to a different bucket. This method uses the
 /// <c>rewriteObject</c> underlying API operation for more flexibility and reliability.
 /// </summary>
 /// <param name="sourceBucket">The name of the bucket containing the object to copy. Must not be null.</param>
 /// <param name="sourceObjectName">The name of the object to copy within the bucket. Must not be null.</param>
 /// <param name="destinationBucket">The name of the bucket to copy the object to. Must not be null.</param>
 /// <param name="destinationObjectName">The name of the object within the destination bucket. Must not be null.</param>
 /// <param name="options">Additional options for the fetch operation. May be null, in which case appropriate
 /// defaults will be used.</param>
 /// <exception cref="ArgumentException">The arguments attempt to copy an object to itself.</exception>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation, with a result returning the
 /// <see cref="Object"/> representation of the new storage object resulting from the copy.</returns>
 public virtual Task <Object> CopyObjectAsync(
     string sourceBucket,
     string sourceObjectName,
     string destinationBucket            = null,
     string destinationObjectName        = null,
     CopyObjectOptions options           = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
        /// <inheritdoc />
        public override Object CopyObject(
            string sourceBucket,
            string sourceObjectName,
            string destinationBucket,
            string destinationObjectName,
            CopyObjectOptions options = null)
        {
            var request  = CreateCopyObjectRequest(sourceBucket, sourceObjectName, destinationBucket, destinationObjectName, options);
            var response = request.Execute();

            while (response.RewriteToken != null)
            {
                request.RewriteToken = response.RewriteToken;
                response             = request.Execute();
            }
            return(response.Resource);
        }
        /// <inheritdoc />
        public override async Task <Object> CopyObjectAsync(
            string sourceBucket,
            string sourceObjectName,
            string destinationBucket,
            string destinationObjectName,
            CopyObjectOptions options           = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var request  = CreateCopyObjectRequest(sourceBucket, sourceObjectName, destinationBucket, destinationObjectName, options);
            var response = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false);

            while (response.RewriteToken != null)
            {
                request.RewriteToken = response.RewriteToken;
                response             = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false);
            }
            return(response.Resource);
        }
        private ObjectsResource.RewriteRequest CreateCopyObjectRequest(
            string sourceBucket,
            string sourceObjectName,
            string destinationBucket,
            string destinationObjectName,
            CopyObjectOptions options)
        {
            GaxPreconditions.CheckNotNull(sourceBucket, nameof(sourceBucket));
            GaxPreconditions.CheckNotNull(sourceObjectName, nameof(sourceObjectName));
            GaxPreconditions.CheckNotNull(destinationBucket, nameof(destinationBucket));
            GaxPreconditions.CheckNotNull(destinationObjectName, nameof(destinationObjectName));
            Object obj     = options?.ExtraMetadata ?? new Object();
            var    request = Service.Objects.Rewrite(obj, sourceBucket, sourceObjectName, destinationBucket, destinationObjectName);

            options?.ModifyRequest(request);
            ApplyEncryptionKey(options?.EncryptionKey, request);
            request.ModifyRequest += (options?.SourceEncryptionKey ?? EncryptionKey).ModifyRequestForRewriteSource;
            return(request);
        }
示例#6
0
        private ObjectsResource.RewriteRequest CreateCopyObjectRequest(
            string sourceBucket,
            string sourceObjectName,
            string destinationBucket,
            string destinationObjectName,
            CopyObjectOptions options)
        {
            GaxPreconditions.CheckNotNull(sourceBucket, nameof(sourceBucket));
            GaxPreconditions.CheckNotNull(sourceObjectName, nameof(sourceObjectName));
            GaxPreconditions.CheckNotNull(destinationBucket, nameof(destinationBucket));
            GaxPreconditions.CheckNotNull(destinationObjectName, nameof(destinationObjectName));
            if (destinationBucket == sourceBucket && destinationObjectName == sourceObjectName)
            {
                throw new ArgumentException("Cannot copy an object to itself. Specify either a different destination bucket or a different destination object name");
            }
            var request = Service.Objects.Rewrite(new Object(), sourceBucket, sourceObjectName, destinationBucket, destinationObjectName);

            options?.ModifyRequest(request);
            return(request);
        }