public StorageTreeNode GetTreeNode(string strPath) { StorageTreeNode oNode = null; try { using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion)) { string strPrefix = GetDirPath(strPath); Amazon.S3.Model.ListObjectsRequest oRequest = new Amazon.S3.Model.ListObjectsRequest(); oRequest.WithBucketName(m_strBucketName).WithPrefix(strPrefix); using (Amazon.S3.Model.ListObjectsResponse oResponse = oS3Client.ListObjects(oRequest)) { oNode = new StorageTreeNode(strPrefix.Substring(0, strPrefix.Length - 1), true); foreach (Amazon.S3.Model.S3Object entry in oResponse.S3Objects) { AddNodeRecursive(oNode, entry.Key.Substring(strPrefix.Length)); } } } } catch { } return(oNode); }
public ErrorTypes RemovePath(string strPath) { ErrorTypes eResult = ErrorTypes.StorageRemoveDir; try { string strDirKey = GetDirPath(strPath); using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion)) { Amazon.S3.Model.ListObjectsRequest oListObjectsRequest = new Amazon.S3.Model.ListObjectsRequest(); oListObjectsRequest.WithBucketName(m_strBucketName).WithPrefix(strDirKey); using (Amazon.S3.Model.ListObjectsResponse oListObjectsResponse = oS3Client.ListObjects(oListObjectsRequest)) { int nDeletedObjectCount = 0; int nObjectsToDeleteCount = oListObjectsResponse.S3Objects.Count; if (nObjectsToDeleteCount > 0) { Amazon.S3.Model.DeleteObjectsRequest oDeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest(); oDeleteObjectsRequest.WithBucketName(m_strBucketName); foreach (Amazon.S3.Model.S3Object oS3Obj in oListObjectsResponse.S3Objects) { oDeleteObjectsRequest.AddKey(oS3Obj.Key); } using (Amazon.S3.Model.DeleteObjectsResponse oDeleteObjectsResponse = oS3Client.DeleteObjects(oDeleteObjectsRequest)) { nDeletedObjectCount = oDeleteObjectsResponse.DeletedObjects.Count; } } if (nObjectsToDeleteCount == nDeletedObjectCount) { eResult = ErrorTypes.NoError; } } } } catch { } return(eResult); }
public void GetTreeNodeBegin(string strPath, AsyncCallback cb, object oParam) { try { m_oGetTreeNode = new TransportClass(cb, oParam); m_oGetTreeNode.m_oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion); m_oGetTreeNode.m_strPrefix = GetDirPath(strPath); Amazon.S3.Model.ListObjectsRequest oRequest = new Amazon.S3.Model.ListObjectsRequest(); oRequest.WithBucketName(m_strBucketName).WithPrefix(m_oGetTreeNode.m_strPrefix); m_oGetTreeNode.m_oS3Client.BeginListObjects(oRequest, m_oGetTreeNode.m_fCallback, m_oGetTreeNode.m_oParam); } catch { m_oGetTreeNode.m_eError = ErrorTypes.StorageGetInfo; m_oGetTreeNode.DisposeAndCallback(); } }
public ErrorTypes RemovePath(string strPath) { ErrorTypes eResult = ErrorTypes.StorageRemoveDir; try { string strDirKey = GetDirPath(strPath); using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion)) { Amazon.S3.Model.ListObjectsRequest oListObjectsRequest = new Amazon.S3.Model.ListObjectsRequest(); oListObjectsRequest.WithBucketName(m_strBucketName).WithPrefix(strDirKey); using (Amazon.S3.Model.ListObjectsResponse oListObjectsResponse = oS3Client.ListObjects(oListObjectsRequest)) { int nDeletedObjectCount = 0; int nObjectsToDeleteCount = oListObjectsResponse.S3Objects.Count; if (nObjectsToDeleteCount > 0) { Amazon.S3.Model.DeleteObjectsRequest oDeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest(); oDeleteObjectsRequest.WithBucketName(m_strBucketName); foreach (Amazon.S3.Model.S3Object oS3Obj in oListObjectsResponse.S3Objects) { oDeleteObjectsRequest.AddKey(oS3Obj.Key); } using (Amazon.S3.Model.DeleteObjectsResponse oDeleteObjectsResponse = oS3Client.DeleteObjects(oDeleteObjectsRequest)) { nDeletedObjectCount = oDeleteObjectsResponse.DeletedObjects.Count; } } if (nObjectsToDeleteCount == nDeletedObjectCount) eResult = ErrorTypes.NoError; } } } catch { } return eResult; }
public StorageTreeNode GetTreeNode(string strPath) { StorageTreeNode oNode = null; try { using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion)) { string strPrefix = GetDirPath(strPath); Amazon.S3.Model.ListObjectsRequest oRequest = new Amazon.S3.Model.ListObjectsRequest(); oRequest.WithBucketName(m_strBucketName).WithPrefix(strPrefix); using (Amazon.S3.Model.ListObjectsResponse oResponse = oS3Client.ListObjects(oRequest)) { oNode = new StorageTreeNode(strPrefix.Substring(0, strPrefix.Length - 1), true); foreach (Amazon.S3.Model.S3Object entry in oResponse.S3Objects) { AddNodeRecursive(oNode, entry.Key.Substring(strPrefix.Length)); } } } } catch { } return oNode; }
// // GET: /S3Object/ public ActionResult Index(string prefix = "", int maxKeys = 100) { ViewBag.prefix = prefix; ViewBag.maxKeys = maxKeys; var list = new Amazon.S3.Model.ListObjectsRequest(); list.WithBucketName(WebConfigurationManager.AppSettings["UploadBucket"]); if (!String.IsNullOrWhiteSpace(prefix)) { list.WithPrefix(prefix); } list.WithMaxKeys(maxKeys); var response = s3.ListObjects(list); return View(response.S3Objects.Select(e => new S3Object { Key = e.Key, Size = e.Size, LastModified = e.LastModified })); }
// // GET: /S3Object/Edit/5 public ActionResult Edit(string id = null, string prefix = "", int maxKeys = 100) { ViewBag.prefix = prefix; ViewBag.maxKeys = maxKeys; var list = new Amazon.S3.Model.ListObjectsRequest(); list.WithBucketName(WebConfigurationManager.AppSettings["UploadBucket"]); list.WithPrefix(id); var s3Objects = s3.ListObjects(list).S3Objects; if (s3Objects.Count == 0) { return HttpNotFound(); } var get = new Amazon.S3.Model.GetObjectRequest(); get.WithBucketName(WebConfigurationManager.AppSettings["UploadBucket"]); get.WithKey(s3Objects[0].Key); var response = s3.GetObject(get); S3Object modelObject = new S3Object { Key = s3Objects[0].Key, Size = s3Objects[0].Size, LastModified = s3Objects[0].LastModified, ContentType = response.ContentType }; return View(modelObject); }
public ActionResult BulkDeleteConfirmed(string prefix = "", int maxKeys = 100) { if (!String.IsNullOrWhiteSpace(prefix)) { ViewBag.prefix = prefix; ViewBag.maxKeys = maxKeys; var list = new Amazon.S3.Model.ListObjectsRequest(); list.WithBucketName(WebConfigurationManager.AppSettings["UploadBucket"]); if (!String.IsNullOrWhiteSpace(prefix)) { list.WithPrefix(prefix); } list.WithMaxKeys(maxKeys); var keys = s3.ListObjects(list).S3Objects.Select(e => new Amazon.S3.Model.KeyVersion(e.Key)).ToArray(); var bulkDelete = new Amazon.S3.Model.DeleteObjectsRequest(); bulkDelete.WithBucketName(WebConfigurationManager.AppSettings["UploadBucket"]); bulkDelete.WithKeys(keys); s3.DeleteObjects(bulkDelete); } return RedirectToAction("Index", new { prefix = prefix, maxKeys = maxKeys }); }
// // GET: /S3Object/BulkDelete public ActionResult BulkDelete(string prefix = "", int maxKeys = 100) { ViewBag.prefix = prefix; ViewBag.maxKeys = maxKeys; var list = new Amazon.S3.Model.ListObjectsRequest(); list.WithBucketName(WebConfigurationManager.AppSettings["UploadBucket"]); if (!String.IsNullOrWhiteSpace(prefix)) { list.WithPrefix(prefix); } list.WithMaxKeys(maxKeys); var s3Objects = s3.ListObjects(list); List<S3Object> modelObjects = new List<S3Object>(s3Objects.S3Objects.Count); foreach (var s3Object in s3Objects.S3Objects) { modelObjects.Add(new S3Object { Key = s3Object.Key, Size = s3Object.Size, LastModified = s3Object.LastModified }); } return View(modelObjects); }