public GetObjectResponse GetMetadata(string key, bool recoveryIfFolderBroken = false) { S3Service service = connection.Connect (); try{ var request = new LitS3.GetObjectRequest(service, RuntimeSettings.DefaultBucketName, key, true); using (GetObjectResponse response = request.GetResponse()){ return response; } } catch (WebException webx) { if (webx != null && ((HttpWebResponse)webx.Response) != null && ((HttpWebResponse)webx.Response).StatusCode == HttpStatusCode.NotFound) { try { //METADATA NOT FOUND, recover it (if is folder)! if(recoveryIfFolderBroken){ if(key.EndsWith("/")){ GenericCreateFolder(key); Logger.LogInfo("INFO METADATA NOT FOUND", "METADATA FOR "+ key +" NOT FOUND, trying to recover it!"); GetObjectRequest request2 = new LitS3.GetObjectRequest(service, RuntimeSettings.DefaultBucketName, key, true); using (GetObjectResponse response2 = request2.GetResponse()){ Logger.LogInfo("INFO METADATA RECOVERED", "METADATA FOR "+ key +" RECOVERED, folder created!"); return response2; } } } Logger.LogInfo("INFO METADATA NOT RECOVERED", "METADATA FOR "+ key +" CANNOT BE RECOVERED!"); return null; } catch (Exception e){ Logger.LogInfo("ERROR CANNOT RECOVERY METADATA", e); return null; } } else { throw webx; } } }
public bool Exists(string key) { try { S3Service service = connection.Connect(); var request = new LitS3.GetObjectRequest(service, RuntimeSettings.DefaultBucketName, key, true); using (GetObjectResponse response = request.GetResponse()) { //todo... } } catch (WebException webx) { if (((HttpWebResponse)webx.Response).StatusCode == HttpStatusCode.NotFound) return false; else throw webx; } return true; }