Ejemplo n.º 1
0
        /// <summary>
        /// Gets a data stream for an existing object in S3. It is your responsibility to close
        /// the Stream when you are finished.
        /// </summary>
        public Stream GetObjectStream(string bucketName, string key, long from)
        {
            var request = new GetObjectRequest(this, bucketName, key);

            request.AddRange((int)from);
            var response = request.GetResponse();

            return(response.GetResponseStream());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a data stream for an existing object in S3. It is your responsibility to close
        /// the Stream when you are finished.
        /// </summary>
        public Stream GetObjectStream(string bucketName, string key,
                                      out long contentLength, out string contentType)
        {
            var request = new GetObjectRequest(this, bucketName, key);
            GetObjectResponse response = request.GetResponse();

            contentLength = response.ContentLength;
            contentType   = response.ContentType;
            return(response.GetResponseStream());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns true if the given object exists in the given bucket.
        /// </summary>
        public bool ObjectExists(string bucketName, string key)
        {
            var request = new GetObjectRequest(this, bucketName, key, true);

            // This is the recommended method from the S3 API docs.
            try
            {
                using (GetObjectResponse response = request.GetResponse())
                    return(true);
            }
            catch (WebException exception)
            {
                var response = exception.Response as HttpWebResponse;
                if (response != null && response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
 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;
        }