Container for the parameters to the DeleteObjects operation.

This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify up to 1000 keys.

Inheritance: Amazon.Runtime.AmazonWebServiceRequest
        public void TestCleanup()
        {
            try
            {
                var objRequest = new ListObjectsRequest()
                {
                    BucketName = this.bucketName
                };
                using (var objResponse = client.ListObjects(objRequest))
                {
                    var delRequest = new DeleteObjectsRequest()
                    {
                        BucketName = this.bucketName,
                        Quiet = true
                    };
                    delRequest.AddKeys(objResponse.S3Objects.Select(o => new KeyVersion(o.Key)).ToArray());

                    using (var delResponse = client.DeleteObjects(delRequest))
                    {

                    }
                }

                var deleteRequest = new DeleteBucketRequest()
                {
                    BucketName = this.bucketName
                };
                using (var deleteResponse = client.DeleteBucket(deleteRequest)) { }
            }
            catch (Exception ex)
            {
                this.TestContext.WriteLine("Warning: Could not cleanup bucket: {0}.  {1}", this.bucketName, ex);
            }
        }
Esempio n. 2
0
        /// <summary>AWS S3 여러 객체 삭제</summary>
        public DeleteObjectsResponse DeleteObjectList(List<string> pKeyList)
        {
            try
            {
                using (AmazonS3Client client = new AmazonS3Client())
                {
                    DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest();
                    multiObjectDeleteRequest.BucketName = strAwsBucketName;

                    foreach (string key in pKeyList)
                    {
                        multiObjectDeleteRequest.AddKey(key);
                    }

                    DeleteObjectsResponse response = client.DeleteObjects(multiObjectDeleteRequest);

                    //response.DeleteErrors.Count = 실패한 삭제 객체
                    //response.DeletedObjects.Count = 성공한 삭제 객체
                    //.Key, .Code, .Message로 정보 확인 가능.
                    return response;
                }
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                throw amazonS3Exception;
            }
        }
Esempio n. 3
0
        public static AmazonS3Client SetupBlob(string container, string path)
        {
            var request = new ListVersionsRequest
            {
                BucketName = container,
                Prefix = path
            };

            var resp = _client.ListVersions(request);
            var toDelete = resp.Versions.Where(v => v.Key == path).Select(v => new KeyVersion
            {
                Key = v.Key,
                VersionId = v.VersionId
            }).ToList();

            if (toDelete.Any())
            {
                var delRequest = new DeleteObjectsRequest
                {
                    BucketName = container,
                    Objects = toDelete,
                    Quiet = true
                };

                _client.DeleteObjects(delRequest);
            }

            return _client;
        }
        void ICoreAmazonS3.Deletes(string bucketName, IEnumerable<string> objectKeys, IDictionary<string, object> additionalProperties)
        {
            var request = new DeleteObjectsRequest
            {
                BucketName = bucketName
            };

            foreach(var key in objectKeys)
            {
                request.AddKey(key);
            }
            InternalSDKUtils.ApplyValues(request, additionalProperties);
            this.DeleteObjects(request);
        }
        Task ICoreAmazonS3.DeletesAsync(string bucketName, IEnumerable<string> objectKeys, IDictionary<string, object> additionalProperties, CancellationToken cancellationToken)
        {
            var request = new DeleteObjectsRequest
            {
                BucketName = bucketName,
            };

            foreach (var key in objectKeys)
            {
                request.AddKey(key);
            }
            InternalSDKUtils.ApplyValues(request, additionalProperties);
            return this.DeleteObjectsAsync(request, cancellationToken);
        }
        /// <summary>
        /// Deletes all keys in a given bucket, then deletes the bucket itself.
        /// </summary>
        /// <param name="client">The client to use.</param>
        /// <param name="bucketName">The bucket to delete.</param>
        public static void DeleteBucketRecursive(this AmazonS3 client, string bucketName)
        {
            while(true)
            {
                // attempt to delete the bucket
                try
                {
                    var deleteRequest = new DeleteBucketRequest()
                    {
                        BucketName = bucketName
                    };
                    using (var deleteResponse = client.DeleteBucket(deleteRequest))
                    {
                        // deletion was successful
                        return;
                    }
                }
                catch (AmazonS3Exception ex)
                {
                    if (ex.ErrorCode != "BucketNotEmpty") throw ex;
                }

                var objRequest = new ListObjectsRequest()
                {
                    BucketName = bucketName
                };
                using (var objResponse = client.ListObjects(objRequest))
                {
                    var delRequest = new DeleteObjectsRequest()
                    {
                        BucketName = bucketName,
                        Quiet = true
                    };

                    // select the objects to delete (up to the supported limit of 1000)
                    var objToDelete = objResponse.S3Objects.Take(1000).Select(o => new KeyVersion(o.Key));
                    delRequest.AddKeys(objToDelete.ToArray());

                    using (var delResponse = client.DeleteObjects(delRequest))
                    {
                    }
                }
            }
        }
Esempio n. 7
0
        public void DeleteBookData(string key)
        {
            var matchingFilesResponse = _amazonS3.ListObjects(new ListObjectsRequest()
            {
                BucketName = _bucketName,
                Prefix = key
            });
            if (matchingFilesResponse.S3Objects.Count == 0)
                return;

            var deleteObjectsRequest = new DeleteObjectsRequest()
            {
                BucketName = UnitTestBucketName,
                Objects = matchingFilesResponse.S3Objects.Select(s3Object => new KeyVersion() { Key = s3Object.Key }).ToList()
            };

            var response = _amazonS3.DeleteObjects(deleteObjectsRequest);
            Debug.Assert(response.DeleteErrors.Count == 0);
        }
        /// <summary>
        /// Delete a folder
        /// </summary>
        /// <param name="prefix">prefix</param>
        public void DeleteFolder(string prefix)
        {
            // Get all object with specified prefix
            var listRequest = new ListObjectsRequest()
            {
                BucketName = _bucketName,
                Prefix = prefix
            };

            var deleteRequest = new DeleteObjectsRequest
            {
                BucketName = _bucketName
            };

            do
            {
                var listResponse = _client.ListObjects(listRequest);

                // Add all object with specified prefix to delete request.
                foreach (var entry in listResponse.S3Objects)
                {
                    deleteRequest.AddKey(entry.Key);
                }

                if (listResponse.IsTruncated)
                {
                    listRequest.Marker = listResponse.NextMarker;
                }
                else
                {
                    listRequest = null;
                }
            }
            while (listRequest != null);

            // Delete all the object with specified prefix.
            if (deleteRequest.Objects.Count > 0)
            {
                var deleteResponse = _client.DeleteObjects(deleteRequest);
                deleteResponse.DisposeIfDisposable();
            }
        }
        public async Task <DeleteObjectsResponse> DeleteObjectsAsync(string bucket,
                                                                     IEnumerable <string> keys,
                                                                     CancellationToken cancellationToken = default)
        {
            this.Logger.LogDebug($"[{nameof(this.DeleteObjectsAsync)}]");

            this.Logger.LogTrace(JsonConvert.SerializeObject(new { bucket, keys }));

            if (string.IsNullOrWhiteSpace(bucket))
            {
                throw new ArgumentNullException(nameof(bucket));
            }
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }

            var keyVersions = new List <KeyVersion>();

            keyVersions.AddRange(keys.Select(k => new KeyVersion()
            {
                Key = k
            }));

            var request = new Amazon.S3.Model.DeleteObjectsRequest
            {
                BucketName = bucket,
                Objects    = keyVersions,
            };

            this.Logger.LogTrace(JsonConvert.SerializeObject(value: request));

            var response = await this.Repository.DeleteObjectsAsync(request : request,
                                                                    cancellationToken : cancellationToken == default?this.CancellationToken.Token : cancellationToken);

            this.Logger.LogTrace(JsonConvert.SerializeObject(value: response));

            return(response);
        }
        public virtual void DeleteBucket(AmazonS3Client s3Client, string bucketName)
        {
            // First, try to delete the bucket.
            var deleteBucketRequest = new DeleteBucketRequest
            {
                BucketName = bucketName
            };

            try
            {
                s3Client.DeleteBucket(deleteBucketRequest);
                // If we get here, no error was generated so we'll assume the bucket was deleted and return.
                return;
            }
            catch (AmazonS3Exception ex)
            {
                if (!ex.ErrorCode.Equals("BucketNotEmpty"))
                {
                    // We got an unanticipated error. Just rethrow.
                    throw;
                }
            }

            // If we got here, then our bucket isn't empty so we need to delete the items in it first.

            DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest {BucketName = bucketName};

            foreach (S3Object obj in s3Client.ListObjects(new ListObjectsRequest {BucketName = bucketName}).S3Objects)
            {
                // Add keys for the objects to the delete request
                deleteObjectsRequest.AddKey(obj.Key, null);
            }

            // Submit the request
            s3Client.DeleteObjects(deleteObjectsRequest);

            // The bucket is empty now, so delete the bucket.
            s3Client.DeleteBucket(deleteBucketRequest);
        }
        public void Dispose()
        {
            var objectsRequest = new ListObjectsRequest
            {
                BucketName = Config["Bucket"],
                Prefix = ContainerPrefix,
                MaxKeys = 100000
            };

            var keys = new List<KeyVersion>();
            do
            {
                var objectsResponse = _client.ListObjectsAsync(objectsRequest).Result;

                keys.AddRange(objectsResponse.S3Objects
                    .Select(x => new KeyVersion() { Key = x.Key, VersionId = null }));

                // If response is truncated, set the marker to get the next set of keys.
                if (objectsResponse.IsTruncated)
                {
                    objectsRequest.Marker = objectsResponse.NextMarker;
                }
                else
                {
                    objectsRequest = null;
                }
            } while (objectsRequest != null);

            if (keys.Count > 0)
            {
                var objectsDeleteRequest = new DeleteObjectsRequest()
                {
                    BucketName = Config["Bucket"],
                    Objects = keys
                };

                _client.DeleteObjectsAsync(objectsDeleteRequest).Wait();
            }
        }
        private void FindKeys(string BucketName, DeleteObjectsRequest deleteRequest, string SearchString, AmazonS3 Client)
        {
            ListObjectsRequest request = new ListObjectsRequest
            {
                BucketName = BucketName
            };

            using (Client)
            {
                do
                {

                    ListObjectsResponse response = Client.ListObjects(request);
                    foreach (S3Object entry in response.S3Objects)
                    {
                        if (entry.Key.Contains(SearchString))
                        {
                            Project.Log(Level.Info, "Deleting file: {0}", entry.Key);
                            deleteRequest.AddKey(entry.Key, null);
                            numKeys++;
                        }
                    }
                    // If response is truncated, set the marker to get the next
                    // set of keys.
                    if (response.IsTruncated)
                    {
                        request.Marker = response.NextMarker;
                    }
                    else
                    {
                        request = null;
                    }

                } while (request != null);
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Initiates the asynchronous execution of the DeleteObjects operation.
 /// <seealso cref="Amazon.S3.IAmazonS3.DeleteObjects"/>
 /// </summary>
 /// 
 /// <param name="deleteObjectsRequest">Container for the necessary parameters to execute the DeleteObjects operation on AmazonS3.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDeleteObjects
 ///         operation.</returns>
 public IAsyncResult BeginDeleteObjects(DeleteObjectsRequest deleteObjectsRequest, AsyncCallback callback, object state)
 {
     return invokeDeleteObjects(deleteObjectsRequest, callback, state, false);
 }
Esempio n. 14
0
 /// <summary>
 /// <para>This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify up to 1000
 /// keys.</para>
 /// </summary>
 /// 
 /// <param name="deleteObjectsRequest">Container for the necessary parameters to execute the DeleteObjects service method on AmazonS3.</param>
 /// 
 /// <returns>The response from the DeleteObjects service method, as returned by AmazonS3.</returns>
 /// 
 public DeleteObjectsResponse DeleteObjects(DeleteObjectsRequest deleteObjectsRequest)
 {
     IAsyncResult asyncResult = invokeDeleteObjects(deleteObjectsRequest, null, null, true);
     return EndDeleteObjects(asyncResult);
 }
Esempio n. 15
0
        /// <summary>
        /// Removes the manifest and iterates through the parts list to see which parts had been completed when 
        /// failures occur and removes those objects to avoid storage cost to the user (if the user retries the 
        /// command, a different root key guid will be generated leading to potential orphans).
        /// </summary>
        /// <param name="manifestFileKey">The object key of the manifest file.</param>
        /// <param name="partsList">The set of parts that should have been uploaded</param>
        /// <returns>True if all objects were successfully deleted, false if objects remain that the user should manually clean up</returns>
        bool RemoveUploadedArtifacts(string manifestFileKey, IEnumerable<ImageFilePart> partsList)
        {
            var allRemoved = true;

            try
            {
                S3Client.DeleteObject(new DeleteObjectRequest { BucketName = this.BucketName, Key = manifestFileKey });
            }
            catch (Exception)
            {
                allRemoved = false;
            }

            var keysToDelete = (from part in partsList where part.UploadCompleted select part.Key).ToList();

            var keyIndex = 0;
            while (keyIndex < keysToDelete.Count)
            {
                var request = new DeleteObjectsRequest {BucketName = this.BucketName};
                while (keyIndex < keysToDelete.Count && request.Objects.Count <= 1000)
                {
                    request.AddKey(keysToDelete[keyIndex++]);
                }

                try
                {
                    S3Client.DeleteObjects(request);
                }
                catch (Exception)
                {
                    allRemoved = false;
                }
            }

            return allRemoved;
        }
Esempio n. 16
0
 /// <summary>
 /// Initiates the asynchronous execution of the DeleteObjects operation.
 /// </summary>
 /// 
 /// <param name="request">Container for the necessary parameters to execute the DeleteObjects operation on AmazonS3Client.</param>
 /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
 /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 public void DeleteObjectsAsync(DeleteObjectsRequest request, AmazonServiceCallback<DeleteObjectsRequest, DeleteObjectsResponse> callback, AsyncOptions options = null)
 {
     options = options == null?new AsyncOptions():options;
     var marshaller = new DeleteObjectsRequestMarshaller();
     var unmarshaller = DeleteObjectsResponseUnmarshaller.Instance;
     Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
     if(callback !=null )
         callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
             AmazonServiceResult<DeleteObjectsRequest,DeleteObjectsResponse> responseObject 
                     = new AmazonServiceResult<DeleteObjectsRequest,DeleteObjectsResponse>((DeleteObjectsRequest)req, (DeleteObjectsResponse)res, ex , ao.State);    
                 callback(responseObject); 
         };
     BeginInvoke<DeleteObjectsRequest>(request, marshaller, unmarshaller, options, callbackHelper);
 }
Esempio n. 17
0
        public void Delete(string[] keys)
        {
            var request = new DeleteObjectsRequest
            {
                BucketName = BucketName,
                Quiet = true,
                Objects = keys.Select(k => new KeyVersion { Key = ConvertKey(k) }).ToList()
            };

            try
            {
                S3.DeleteObjects(request);
            }
            catch (DeleteObjectsException doe)
            {
                // From http://docs.aws.amazon.com/sdkfornet/latest/apidocs/items/TS3DeleteObjectsRequest_NET4_5.html
                var errorResponse = doe.Response;
                foreach (var deleteError in errorResponse.DeleteErrors)
                {
                    Log.Error("Error deleting item " + deleteError.Key);
                    Log.Error(" Code - " + deleteError.Code);
                    Log.Error(" Message - " + deleteError.Message);
                }

                throw;
            }
        }
Esempio n. 18
0
        private Amazon.S3.Model.DeleteObjectsResponse CallAWSServiceOperation(IAmazonS3 client, Amazon.S3.Model.DeleteObjectsRequest request)
        {
            Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon S3", "DeleteObject");

            try
            {
#if DESKTOP
                return(client.DeleteObjects(request));
#elif CORECLR
                return(client.DeleteObjectsAsync(request).GetAwaiter().GetResult());
#else
#error "Unknown build edition"
#endif
            }
            catch (AmazonServiceException exc)
            {
                var webException = exc.InnerException as System.Net.WebException;
                if (webException != null)
                {
                    throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
                }

                throw;
            }
        }
Esempio n. 19
0
        /// <summary>
        /// <para>This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify up to 1000
        /// keys.</para>
        /// </summary>
        /// 
        /// <param name="deleteObjectsRequest">Container for the necessary parameters to execute the DeleteObjects service method on AmazonS3.</param>
        /// 
        /// <returns>The response from the DeleteObjects service method, as returned by AmazonS3.</returns>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public async Task<DeleteObjectsResponse> DeleteObjectsAsync(DeleteObjectsRequest deleteObjectsRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DeleteObjectsRequestMarshaller();
            var unmarshaller = DeleteObjectsResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, DeleteObjectsRequest, DeleteObjectsResponse>(deleteObjectsRequest, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
        public virtual async Task<bool> DeleteDirectory(string folderPath)
        {
            List<FileDetails> files = new List<FileDetails>();
            bool completed = false;

            try
            {
                IAmazonS3 client = GetS3Client();
                int deleteRounds = 0;

                while(true)
                {
                    if(deleteRounds >= AmazonConstansts.MAX_DELETE_ROUNDS)
                    {                        
                        _logger.Error(MessageResources.MaxDeleteRoundsExceptions, AmazonConstansts.MAX_DELETE_ROUNDS);
                        return false;
                    }
                    deleteRounds++;

                    //list
                    ListObjectsRequest listRequest = new ListObjectsRequest()
                    {
                        BucketName = Settings.BucketName,
                        Prefix = folderPath,
                        MaxKeys = AmazonConstansts.MAX_OBJECTS_DELETED
                    };

                    ListObjectsResponse listResponse = await client.ListObjectsAsync(listRequest);
                                                        
                    //delete
                    List<KeyVersion> objects = listResponse.S3Objects
                        .Select(p => new KeyVersion() { Key = p.Key }).ToList();

                    if(objects.Count == 0)
                    {
                        break;
                    }

                    DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest()
                    {
                        BucketName = Settings.BucketName,
                        Objects = objects
                    };
                    DeleteObjectsResponse deleteResponse = await client.DeleteObjectsAsync(deleteRequest);
                }                

                completed = true;
            }
            catch (AmazonS3Exception ex)
            {
                _logger.Exception(ex);
            }
            
            return completed;
        }
        public virtual async Task<bool> Delete(List<string> namePaths)
        {
            bool completed = false;

            try
            {
                IAmazonS3 client = GetS3Client();

                DeleteObjectsRequest request = new DeleteObjectsRequest()
                {
                    BucketName = Settings.BucketName,
                    Objects = namePaths.Select(p => new KeyVersion() { Key = p }).ToList()
                };

                DeleteObjectsResponse response = await client.DeleteObjectsAsync(request);

                completed = true;
            }
            catch (AmazonS3Exception ex)
            {
                _logger.Exception(ex);
            }
            
            return completed;
        }
Esempio n. 22
0
        /// <summary>
        /// <para>This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify up to 1000
        /// keys.</para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteObjects service method on AmazonS3.</param>
        /// 
        /// <returns>The response from the DeleteObjects service method, as returned by AmazonS3.</returns>
		public DeleteObjectsResponse DeleteObjects(DeleteObjectsRequest request)
        {
            var task = DeleteObjectsAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
Esempio n. 23
0
        internal DeleteObjectsResponse DeleteObjects(DeleteObjectsRequest request)
        {
            var marshaller = new DeleteObjectsRequestMarshaller();
            var unmarshaller = DeleteObjectsResponseUnmarshaller.Instance;

            return Invoke<DeleteObjectsRequest,DeleteObjectsResponse>(request, marshaller, unmarshaller);
        }
Esempio n. 24
0
            /// <summary>
            /// Removes all objects from the bucket
            /// </summary>
            /// <param name="prefix">Only delete objects that begin with the specified prefix.</param>
            /// <param name="lastModified">Only delete objects that where modified prior to this date.</param>
            /// <param name="settings">The <see cref="S3Settings"/> required to delete from Amazon S3.</param>
            public IList<string> DeleteAll(string prefix, DateTimeOffset lastModified, S3Settings settings)
            {
                //Get S3 Objects
                IList<S3Object> objects = this.GetObjects(prefix, settings);
                List<string> list = new List<string>();
                foreach (S3Object obj in objects)
                {
                    if ((lastModified == DateTimeOffset.MinValue) && (obj.LastModified < lastModified))
                    {
                        list.Add(obj.Key);
                    }
                }



                //Delete
                AmazonS3Client client = this.GetClient(settings);

                while (list.Count > 0)
                {
                    int max = list.Count;
                    if (max > 1000)
                    {
                        max = 1000;
                    }

                    DeleteObjectsRequest request = new DeleteObjectsRequest();
                    request.BucketName = settings.BucketName;
                
                    for (int index = 0; index < max; index++)
                    {
                        request.AddKey(list[index]);
                    }

                    client.DeleteObjects(request);
                    _Log.Verbose("Deleting {0} objects from bucket {1}...", max, settings.BucketName);

                    list.RemoveRange(0, max);
                }
                
                return list;
            }
Esempio n. 25
0
 IAsyncResult invokeDeleteObjects(DeleteObjectsRequest deleteObjectsRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new DeleteObjectsRequestMarshaller().Marshall(deleteObjectsRequest);
     var unmarshaller = DeleteObjectsResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
Esempio n. 26
0
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteObjects operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteObjects operation on AmazonS3Client.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDeleteObjects
        ///         operation.</returns>
        public IAsyncResult BeginDeleteObjects(DeleteObjectsRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new DeleteObjectsRequestMarshaller();
            var unmarshaller = DeleteObjectsResponseUnmarshaller.Instance;

            return BeginInvoke<DeleteObjectsRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
Esempio n. 27
0
        /// <summary>
        /// <para>This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify up to 1000
        /// keys.</para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteObjects service method on AmazonS3.</param>
        /// 
        /// <returns>The response from the DeleteObjects service method, as returned by AmazonS3.</returns>
		public DeleteObjectsResponse DeleteObjects(DeleteObjectsRequest request)
        {
            var task = DeleteObjectsAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
        /// <summary>
        /// Delete Objects in S3 Bucket
        /// </summary>
        public void DeleteObject()
        {
            ResultText.text = string.Format("deleting {0} from bucket {1}", SampleFileName, S3BucketName);
            List<KeyVersion> objects = new List<KeyVersion>();
            objects.Add(new KeyVersion()
            {
                Key = SampleFileName
            });

            var request = new DeleteObjectsRequest()
            {
                BucketName = S3BucketName,
                Objects = objects
            };

            Client.DeleteObjectsAsync(request, (responseObj) =>
            {
                ResultText.text += "\n";
                if (responseObj.Exception == null)
                {
                    ResultText.text += "Got Response \n \n";

                    ResultText.text += string.Format("deleted objects \n");

                    responseObj.Response.DeletedObjects.ForEach((dObj) =>
                    {
                        ResultText.text += dObj.Key;
                    });
                }
                else
                {
                    ResultText.text += "Got Exception \n";
                }
            });
        }
Esempio n. 29
0
 public static Task<DeleteObjectsResponse> DeleteObjectsAsync(
     this AmazonS3 client, DeleteObjectsRequest request)
 {
     IAsyncResult ar = client.BeginDeleteObjects(request, null, null);
     return Task.Factory.FromAsync<DeleteObjectsResponse>(ar, client.EndDeleteObjects);
 }
Esempio n. 30
0
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteObjects operation.
        /// <seealso cref="Amazon.S3.IAmazonS3.DeleteObjects"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteObjects operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public Task<DeleteObjectsResponse> DeleteObjectsAsync(DeleteObjectsRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DeleteObjectsRequestMarshaller();
            var unmarshaller = DeleteObjectsResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, DeleteObjectsRequest, DeleteObjectsResponse>(request, marshaller, unmarshaller, signer, cancellationToken);
        }
Esempio n. 31
0
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteObjects operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteObjects operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<DeleteObjectsResponse> DeleteObjectsAsync(DeleteObjectsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DeleteObjectsRequestMarshaller();
            var unmarshaller = DeleteObjectsResponseUnmarshaller.Instance;

            return InvokeAsync<DeleteObjectsRequest,DeleteObjectsResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
Esempio n. 32
0
 public async Task<IHttpActionResult> Delete()
 {
     var bucketRequest = new DeleteBucketRequest
     {
         BucketName = TestBucketName,
         BucketRegion = S3Region.EUC1
     };
     var request = new DeleteObjectsRequest
     {
         BucketName = TestBucketName,
         Objects = new List<KeyVersion>
         {
             new KeyVersion { Key = "test1.txt" },
             new KeyVersion { Key = "test2.txt" },
             new KeyVersion { Key = "test3.txt" },
             new KeyVersion { Key = "test4.txt" },
             new KeyVersion { Key = "test5.txt" },
             new KeyVersion { Key = "test6.txt" },
             new KeyVersion { Key = "test7.txt" },
             new KeyVersion { Key = "test8.txt" },
             new KeyVersion { Key = "test9.txt" },
             new KeyVersion { Key = "test10.txt" }
         }
     };
     await _client.DeleteObjectsAsync(request);
     await _client.DeleteBucketAsync(bucketRequest);
     return Ok();
 }