public async Task <IStorageObject> GetObject(string bucketName, string objectName, CancellationToken token = default)
        {
            var stream = new MemoryStream();

            await _client.GetObjectAsync(bucketName, objectName, input => input.CopyTo(stream), cancellationToken : token);

            Minio.DataModel.ObjectStat stats = await _client.StatObjectAsync(bucketName, objectName, cancellationToken : token);

            var dictionary = new Dictionary <string, string>();

            foreach (var pair in stats.MetaData)
            {
                dictionary.Add(pair.Key, pair.Value);
            }

            return(new StorageObject
            {
                ContentType = stats.ContentType,
                Data = stream,
                Metadata = dictionary,
                Name = stats.ObjectName,
                Size = stats.Size,
                LastModified = stats.LastModified
            });
        }
예제 #2
0
        public static ObjectStat FromResponseHeaders(string objectName, IList <Parameter> responseHeaders)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException("Name of an object cannot be empty");
            }
            ObjectStat objInfo = new ObjectStat();

            foreach (Parameter parameter in responseHeaders)
            {
                switch (parameter.Name.ToLower())
                {
                case "content-length":
                    objInfo.Size = long.Parse(parameter.Value.ToString());
                    break;

                case "last-modified":
                    objInfo.LastModified = DateTime.Parse(parameter.Value.ToString(), CultureInfo.InvariantCulture);
                    break;

                case "etag":
                    objInfo.ETag = parameter.Value.ToString().Replace("\"", string.Empty);
                    break;

                case "Content-Type":
                    objInfo.ContentType = parameter.Value.ToString();
                    objInfo.MetaData["Content-Type"] = objInfo.ContentType;
                    break;

                case "x-amz-version-id":
                    objInfo.VersionId = parameter.Value.ToString();
                    break;

                case "x-amz-delete-marker":
                    objInfo.DeleteMarker = parameter.Value.ToString().Equals("true");
                    break;

                default:
                    if (OperationsUtil.IsSupportedHeader(parameter.Name))
                    {
                        objInfo.MetaData[parameter.Name] = parameter.Value.ToString();
                    }
                    else if (parameter.Name.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase))
                    {
                        objInfo.MetaData[parameter.Name.Substring("x-amz-meta-".Length)] = parameter.Value.ToString();
                    }
                    else
                    {
                        objInfo.ExtraHeaders[parameter.Name] = parameter.Value.ToString();
                    }
                    break;
                }
            }

            return(objInfo);
        }
예제 #3
0
        public static ObjectStat FromResponseHeaders(string objectName, Dictionary <string, string> responseHeaders)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException("Name of an object cannot be empty");
            }
            ObjectStat objInfo = new ObjectStat();

            objInfo.ObjectName = objectName;
            foreach (var paramName in responseHeaders.Keys)
            {
                string paramValue = responseHeaders[paramName];
                switch (paramName.ToLower())
                {
                case "content-length":
                    objInfo.Size = long.Parse(paramValue);
                    break;

                case "last-modified":
                    objInfo.LastModified = DateTime.Parse(paramValue, CultureInfo.InvariantCulture);
                    break;

                case "etag":
                    objInfo.ETag = paramValue.Replace("\"", string.Empty);
                    break;

                case "content-type":
                    objInfo.ContentType = paramValue.ToString();
                    objInfo.MetaData["Content-Type"] = objInfo.ContentType;
                    break;

                case "x-amz-version-id":
                    objInfo.VersionId = paramValue;
                    break;

                case "x-amz-delete-marker":
                    objInfo.DeleteMarker = paramValue.Equals("true");
                    break;

                case "x-amz-archive-status":
                    objInfo.ArchiveStatus = paramValue.ToString();
                    break;

                case "x-amz-tagging-count":
                    if (Int32.TryParse(paramValue.ToString(), out int tagCount) && tagCount >= 0)
                    {
                        objInfo.TaggingCount = (uint)tagCount;
                    }
                    break;

                case "x-amz-expiration":
                    // x-amz-expiration header includes the expiration date and the corresponding rule id.
                    string expirationResponse = paramValue.ToString().Trim();
                    string expiryDatePattern  = @"(Sun|Mon|Tue|Wed|Thu|Fri|Sat), \d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} [A-Z]+";
                    Match  expiryMatch        = Regex.Match(expirationResponse, expiryDatePattern);
                    if (expiryMatch.Success)
                    {
                        objInfo.Expires = DateTime.SpecifyKind(
                            DateTime.Parse(expiryMatch.Value),
                            DateTimeKind.Utc);
                    }
                    break;

                case "x-amz-object-lock-mode":
                    Console.WriteLine(paramValue.ToString());
                    if (!string.IsNullOrWhiteSpace(paramValue.ToString()))
                    {
                        objInfo.ObjectLockMode = (paramValue.ToString().ToLower().Equals("governance"))?RetentionMode.GOVERNANCE:RetentionMode.COMPLIANCE;
                    }
                    break;

                case "x-amz-object-lock-retain-until-date":
                    Console.WriteLine(paramValue.ToString());
                    string lockUntilDate = paramValue.ToString();
                    if (!string.IsNullOrWhiteSpace(lockUntilDate))
                    {
                        objInfo.ObjectLockRetainUntilDate = DateTime.SpecifyKind(
                            DateTime.Parse(lockUntilDate),
                            DateTimeKind.Utc);;
                    }
                    break;

                case "x-amz-object-lock-legal-hold":
                    string legalHoldON = paramValue.ToString().Trim();
                    if (!string.IsNullOrWhiteSpace(legalHoldON))
                    {
                        objInfo.LegalHoldEnabled = legalHoldON.ToLower().Equals("on");
                    }
                    break;

                default:
                    if (OperationsUtil.IsSupportedHeader(paramName))
                    {
                        objInfo.MetaData[paramName] = paramValue;
                    }
                    else if (paramName.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase))
                    {
                        objInfo.MetaData[paramName.Substring("x-amz-meta-".Length)] = paramValue;
                    }
                    else
                    {
                        objInfo.ExtraHeaders[paramName] = paramValue;
                    }
                    break;
                }
            }

            return(objInfo);
        }
예제 #4
0
        public static ObjectStat FromResponseHeaders(string objectName, Dictionary <string, string> responseHeaders)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException("Name of an object cannot be empty");
            }
            ObjectStat objInfo = new ObjectStat();

            objInfo.ObjectName = objectName;
            foreach (var paramName in responseHeaders.Keys)
            {
                string paramValue = responseHeaders[paramName];
                switch (paramName.ToLower())
                {
                case "content-length":
                    objInfo.Size = long.Parse(paramValue);
                    break;

                case "last-modified":
                    objInfo.LastModified = DateTime.Parse(paramValue, CultureInfo.InvariantCulture);
                    break;

                case "etag":
                    objInfo.ETag = paramValue.Replace("\"", string.Empty);
                    break;

                case "content-type":
                    objInfo.ContentType = paramValue.ToString();
                    objInfo.MetaData["Content-Type"] = objInfo.ContentType;
                    break;

                case "x-amz-version-id":
                    objInfo.VersionId = paramValue;
                    break;

                case "x-amz-delete-marker":
                    objInfo.DeleteMarker = paramValue.Equals("true");
                    break;

                case "x-amz-tagging-count":
                    if (Int32.TryParse(paramValue.ToString(), out int tagCount) && tagCount >= 0)
                    {
                        objInfo.TaggingCount = (uint)tagCount;
                    }
                    break;

                default:
                    if (OperationsUtil.IsSupportedHeader(paramName))
                    {
                        objInfo.MetaData[paramName] = paramValue;
                    }
                    else if (paramName.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase))
                    {
                        objInfo.MetaData[paramName.Substring("x-amz-meta-".Length)] = paramValue;
                    }
                    else
                    {
                        objInfo.ExtraHeaders[paramName] = paramValue;
                    }
                    break;
                }
            }

            return(objInfo);
        }