Ejemplo n.º 1
0
Archivo: S3V4.cs Proyecto: zhabis/nfx
        public static void SetACL(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, string acl,
                                  int timeoutMs)
        {
            var queryParams = new Dictionary <string, string>()
            {
                { "acl", string.Empty }
            };

            MemoryStream aclStream = new MemoryStream(Encoding.UTF8.GetBytes(acl ?? string.Empty));

            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath, queryParams);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "PUT",
                ItemLocalPath = itemLocalPath,
                QueryParams   = queryParams,
                ContentStream = aclStream
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "PUT", aclStream, headers, timeoutMs);

            request.GetHeaders();
        }
Ejemplo n.º 2
0
Archivo: S3V4.cs Proyecto: zhabis/nfx
        public static void RemoveItem(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, int timeoutMs)
        {
            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "DELETE",
                ItemLocalPath = itemLocalPath
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "DELETE", EMPTY_CONTENT_STREAM, headers, timeoutMs);

            request.GetHeaders(HttpStatusCode.NoContent);
        }
Ejemplo n.º 3
0
Archivo: S3V4.cs Proyecto: zhabis/nfx
        public static IDictionary <string, string> GetItemMetadata(string itemLocalPath, string accessKey, string secretKey,
                                                                   string bucket, string region, int timeoutMs)
        {
            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey, SecretKey = secretKey,
                Bucket        = bucket, Region = region,
                Method        = "HEAD",
                ItemLocalPath = itemLocalPath
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "HEAD", new MemoryStream(), headers, timeoutMs);

            var resultHeaders = S3V4HttpHelpers.GetHeaders(request);

            return(resultHeaders);
        }
Ejemplo n.º 4
0
Archivo: S3V4.cs Proyecto: zhabis/nfx
        public static void GetFile(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, Stream stream,
                                   int timeoutMs)
        {
            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "GET",
                ItemLocalPath = itemLocalPath
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "GET", new MemoryStream(), headers, timeoutMs);

            request.GetResponseBytes(stream);
        }
Ejemplo n.º 5
0
Archivo: S3V4.cs Proyecto: zhabis/nfx
        public static string ListBucket(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, int timeoutMs,
                                        string prefix = null, string marker = null, int?maxKeys = null)
        {
            var queryParams = new Dictionary <string, string>();

            if (prefix != null)
            {
                queryParams.Add("prefix", prefix);
            }

            if (marker != null)
            {
                queryParams.Add("marker", marker);
            }

            if (maxKeys.HasValue)
            {
                queryParams.Add("max-keys", maxKeys.Value.ToString());
            }

            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, "", queryParams);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "GET"
                , QueryParams = queryParams
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "GET", EMPTY_CONTENT_STREAM, headers, timeoutMs);

            string responseStr = request.GetResponseStr();

            return(responseStr);
        }
Ejemplo n.º 6
0
Archivo: S3V4.cs Proyecto: zhabis/nfx
        public static string PutItem(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, Stream contentStream,
                                     int timeoutMs)
        {
            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "PUT",
                ItemLocalPath = itemLocalPath,
                ContentStream = contentStream
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "PUT", contentStream, headers, timeoutMs);

            var resultHeaders = request.GetHeaders();

            return(resultHeaders["ETag"]);
        }