Exemple #1
0
        private void buttonDeleteObject_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.listBoxObjects.SelectedItem == null)
                {
                    return;
                }

                ConfirmDeleteForm confirmDeleteForm = new ConfirmDeleteForm(this.listBoxObjects.SelectedItem.ToString());
                if (confirmDeleteForm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // The first thing we need to do is check for the presence of a Temporary Redirect.  These occur for a few
                // minutes after an EU bucket is created, while S3 creates the DNS entries.  If we get one, we need to delete
                // the file from the redirect URL

                String redirectUrl = null;
                using (BucketListRequest testRequest = new BucketListRequest(this.comboBoxBucketNames.SelectedItem.ToString()))
                {
                    testRequest.Method = "HEAD";
                    using (BucketListResponse testResponse = service.BucketList(testRequest))
                    {
                        if (testResponse.StatusCode == System.Net.HttpStatusCode.TemporaryRedirect)
                        {
                            redirectUrl = testResponse.Headers["Location"].ToString() + this.listBoxObjects.SelectedItem.ToString();
                        }
                    }
                }

                using (ObjectDeleteRequest request = new ObjectDeleteRequest(this.comboBoxBucketNames.SelectedItem.ToString(), this.listBoxObjects.SelectedItem.ToString()))
                {
                    request.RedirectUrl = redirectUrl;
                    using (ObjectDeleteResponse response = service.ObjectDelete(request))
                    { }
                }
                this.ListBucket(this.comboBoxBucketNames.SelectedItem.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
 /// <summary>
 /// Deletes an object from a bucket
 /// </summary>
 public void DeleteObject(String bucketName, String keyName)
 {
     using (ObjectDeleteRequest objectDeleteRequest = new ObjectDeleteRequest(bucketName, keyName))
         using (ObjectDeleteResponse objectDeleteResponse = service.ObjectDelete(objectDeleteRequest))
         { }
 }