Example #1
0
        public string GetUrlByFormatSizeQuality(IStorageInfo storageInfo, MediaElementUrlType urlType,
                                                string filePath, string fileName, string format, int maxWidthHeight, int percentage)
        {
            string sizeQualityString = BuildFormatSizeAndPercentage(format, maxWidthHeight, percentage);

            return(GetUrlCustom(storageInfo, urlType, filePath, fileName, sizeQualityString));

            //if (mode == StorageMode.External)
            //{
            //    return $"{downloadHost}?{sizeQualityString}";
            //}
            //else
            //{
            //    CloudBlobContainer container = GetContainer(storageId, storageAccessKey, mode, filePath);

            //    if (string.IsNullOrEmpty(filePath))
            //    {
            //        filePath = DEFAULT_CONTAINER;
            //    }

            //    // write a blob to the container
            //    CloudBlockBlob blob = container.GetBlockBlobReference(
            //        Path.Combine(filePath, fileName));
            //    var temp = blob.ExistsAsync();
            //    temp.Wait();
            //    if (temp.Result == false)
            //        return string.Empty;

            //    Uri uri = blob.StorageUri.PrimaryUri;
            //    Uri result = new Uri(uri.AbsoluteUri + "?" + sizeQualityString);

            //    return result.AbsoluteUri;
            //}
        }
Example #2
0
        public string GetUrlByStyle(IStorageInfo storageInfo, MediaElementUrlType urlType,
                                    string filePath, string fileName, string styleName)
        {//Azure不支持Style
            return(GetUrlCustom(storageInfo, urlType, filePath, fileName, styleName));

            //if (mode == StorageMode.External)
            //{
            //    return $"{downloadHost}?{styleName}";
            //}
            //else
            //{
            //    CloudBlobContainer container = GetContainer(storageId, storageAccessKey, mode, filePath);

            //    if (string.IsNullOrEmpty(filePath))
            //    {
            //        filePath = DEFAULT_CONTAINER;
            //    }

            //    // write a blob to the container
            //    CloudBlockBlob blob = container.GetBlockBlobReference(
            //        Path.Combine(filePath, fileName));
            //    var temp = blob.ExistsAsync();
            //    temp.Wait();
            //    if (temp.Result == false)
            //        return string.Empty;

            //    Uri uri = blob.StorageUri.PrimaryUri;
            //    Uri result = new Uri(uri.AbsoluteUri + "?" + styleName);

            //    return result.AbsoluteUri;
            //}
        }
Example #3
0
        public async Task <UrlsResponseResult> GetUrlsAsync(string[] objectIds, MediaElementUrlType type,
                                                            string format = "", int maxWidthHeight = 10000, int percentage = 100)
        {
            long   dt        = DateTimeUtils.GetCurrentMillisecondsTimestamp();
            string appsecret = this._appSecret;
            string path      = "/api/images/geturlsbysize";

            string sign = HashUtils.OpenApiSign(this._appId,
                                                this._appSecret, dt, path);
            //{appsecret}!@{appid}#{timestamp}&{content}

            var res = await _client.Post(
                $"{_hostAndPort.ToString().Trim(new char[] { })}/api/images/geturlsbysize")
                      .Header("appId", this._appId).Header("ts", dt).Header("sign", sign)
                      .JsonData <GetUrlsBySizeRequest>(new GetUrlsBySizeRequest()
            {
                ObjectIds      = objectIds,
                Type           = (int)type,
                Format         = format,
                MaxWidthHeight = maxWidthHeight,
                Percentage     = percentage
            })
                      .ResultAsync();

            var obj = JObject.Parse(res).ToObject(typeof(UrlsResponseResult));

            return(obj as UrlsResponseResult);
        }
Example #4
0
        public string GetUrlCustom(Storage storage, string filePath, string fileName,
                                   MediaElementUrlType type, string customStyleProcessStr)
        {
            IStorageProvider storageProvider = StorageProviderFactory.GetStorageProvider(
                _serviceProvider, storage.StorageType);

            switch (type)
            {
            case MediaElementUrlType.DownloadUrl:
            {
                return(storageProvider.GetUrlCustom(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Intranet,
                        StorageAccessKey = storage.StorageAccessKey,
                        StorageId = storage.StorageId,
                        StorageHost = storage.DownloadHost,
                    }, type, filePath, fileName, customStyleProcessStr));
            }

            case MediaElementUrlType.OutputUrl:
            {
                return(storageProvider.GetUrlCustom(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Internet,
                        StorageAccessKey = storage.StorageAccessKey,
                        StorageId = storage.StorageId,
                        StorageHost = storage.OutputHost,
                    }, type, filePath, fileName, customStyleProcessStr));
            }

            case MediaElementUrlType.PublishDownloadUrl:
            {
                return(storageProvider.GetUrlCustom(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Intranet,
                        StorageAccessKey = storage.PublishStorageAccessKey,
                        StorageId = storage.PublishStorageId,
                        StorageHost = storage.PublishOutputHost,
                    }, type, filePath, fileName, customStyleProcessStr));
            }

            default:
            {
                return(storageProvider.GetUrlCustom(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Internet,
                        StorageAccessKey = storage.PublishStorageAccessKey,
                        StorageId = storage.PublishStorageId,
                        StorageHost = storage.PublishOutputHost,
                    }, type, filePath, fileName, customStyleProcessStr));
            }
            }
        }
Example #5
0
        public string GetUrlCustom(IStorageInfo storageInfo, MediaElementUrlType urlType,
                                   string filePath, string fileName, string customStyleProcessStr)
        {
            if (!string.IsNullOrEmpty(filePath))
            {
                filePath = filePath.Trim('/');
            }
            fileName = fileName.Trim('/');
            if (!string.IsNullOrEmpty(customStyleProcessStr))
            {
                customStyleProcessStr = "?" + customStyleProcessStr;
            }
            if (urlType == MediaElementUrlType.PublishDownloadUrl || urlType == MediaElementUrlType.PublishOutputUrl)
            {
                filePath = (!string.IsNullOrEmpty(filePath) ? filePath + "/" : "") + fileName + customStyleProcessStr;
                var downloadHost = storageInfo.StorageHost.Trim('/');
                return($"{downloadHost}/{EXTERNAL_CONTAINER}/{filePath}");
            }
            else
            {
                CloudBlobContainer container = GetContainer(storageInfo.StorageId, storageInfo.StorageAccessKey, StorageMode.Internal, filePath);
                filePath = (!string.IsNullOrEmpty(filePath) ? filePath + "/" : "") + fileName;// + customStyleProcessStr;
                // write a blob to the container
                CloudBlockBlob blob = container.GetBlockBlobReference(filePath);
                var            temp = blob.ExistsAsync();
                temp.Wait();
                if (temp.Result == false)
                {
                    return(string.Empty);
                }

                Uri uri = blob.StorageUri.PrimaryUri;
                if (!string.IsNullOrEmpty(customStyleProcessStr))
                {
                    uri = new Uri(blob.StorageUri.PrimaryUri.AbsoluteUri + customStyleProcessStr);
                }

                var sasConstraints = new SharedAccessBlobPolicy();
                sasConstraints.SharedAccessStartTime  = DateTime.UtcNow.AddMinutes(-5);
                sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(60);
                sasConstraints.Permissions            = SharedAccessBlobPermissions.Read;
                SharedAccessBlobHeaders sasHeaders = new SharedAccessBlobHeaders();
                sasHeaders.ContentType = this.GetContentType(fileName, customStyleProcessStr, sasHeaders.ContentType);

                var sasBlobToken = blob.GetSharedAccessSignature(sasConstraints, sasHeaders);

                if (uri.AbsoluteUri.LastIndexOf('?') > 0)
                {
                    return($"{uri.AbsoluteUri}&{sasBlobToken.Trim('?')}");
                }

                return(uri.AbsoluteUri + sasBlobToken);
            }
        }
Example #6
0
        public async Task <UrlResponseResult> GetUrlAsync(string objectId, MediaElementUrlType type,
                                                          string format = "", int maxWidthHeight = 10000, int percentage = 100)
        {
            long dt = Celia.io.Core.MicroServices.Utilities.DateTimeUtils
                      .GetCurrentMillisecondsTimestamp();
            string appsecret = this._appSecret;
            string path      = "/api/images/geturlbysize";

            string sign = HashUtils.OpenApiSign(this._appId,
                                                this._appSecret, dt, path);
            //{appsecret}!@{appid}#{timestamp}&{content}

            var request = _client.Get(
                $"{_hostAndPort.ToString().Trim(new char[] { })}/api/images/geturlbysize")
                          .Header("appId", this._appId).Header("ts", dt).Header("sign", sign)
                          .UrlData("objectId", objectId).UrlData("type", (int)type);

            if (!string.IsNullOrEmpty(format))
            {
                request = request.UrlData("format", format);
            }
            if (maxWidthHeight < 4096)
            {
                request = request.UrlData("maxWidthHeight", maxWidthHeight);
            }
            if (percentage > 0 && percentage < 100)
            {
                request = request.UrlData("percentage", percentage);
            }

            //[FromQuery] [Required] string objectId,
            //    [FromQuery]
            //[Required]
            //int type,
            //    [FromQuery] string format = "",
            //    [FromQuery] int maxWidthHeight = 10000,
            //    [FromQuery] int percentage = 100
            //

            var res = await request.ResultAsync();

            var obj = JObject.Parse(res).ToObject(typeof(UrlResponseResult));

            return(obj as UrlResponseResult);
        }
Example #7
0
        public async Task <string[]> GetUrlsAsync(string[] objectIds,
                                                  MediaElementUrlType type, string format, int maxWidthHeight, int percentage)
        {
            IEnumerable <ImageElement> imageElements
                = _repository.GetImagesById(objectIds).ToArray();

            var storageIds = imageElements.Select(m => m.StorageId);

            IEnumerable <Storage> storages
                = _repository.GetStoragesByIds(storageIds).ToArray();

            List <string> urls = new List <string>();

            foreach (var objId in objectIds)
            {
                ImageElement element = imageElements.FirstOrDefault(
                    m => m.ObjectId.Equals(objId));
                if (element == null)
                {
                    urls.Add(string.Empty);
                    continue;
                }

                Storage storage = storages.FirstOrDefault(
                    m => m.StorageId.Equals(element.StorageId));
                if (storage == null)
                {
                    urls.Add(string.Empty);
                    continue;
                }

                string url = _storageService.GetUrlByFormatSizeQuality(
                    storage, element.FilePath, element.GetFileName(),
                    type, format, maxWidthHeight, percentage);

                urls.Add(url);
            }

            return(urls.ToArray());
        }
Example #8
0
        public async Task <string> GetUrlAsync(string objectId, MediaElementUrlType type,
                                               string styleName)
        {
            ImageElement element = _repository.FindImageElementById(objectId);

            if (element == null)
            {
                return(string.Empty);
            }

            Storage storage = _storageService.FindStorageById(element.StorageId);

            if (storage == null)
            {
                return(string.Empty);
            }

            string url = _storageService.GetUrlByStyle(storage,
                                                       element.FilePath, element.GetFileName(), type, styleName);

            return(url);
        }
Example #9
0
        public string GetUrlCustom(IStorageInfo storageInfo, MediaElementUrlType urlType, string filePath, string fileName, string customStyleProcessStr)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                filePath = DEFAULT_CONTAINER;
            }
            filePath = filePath.Trim('/');
            fileName = fileName.Trim('/');
            if (urlType == MediaElementUrlType.PublishOutputUrl || urlType == MediaElementUrlType.PublishDownloadUrl)
            {
                var downloadHost = storageInfo.StorageHost.Trim('/');
                if (!string.IsNullOrEmpty(customStyleProcessStr))
                {
                    customStyleProcessStr = "?x-oss-process=" + customStyleProcessStr;
                }
                return($"{downloadHost}/{filePath}/{fileName}{customStyleProcessStr}");
            }
            else
            {
                string    bucketName, objectName;
                OssClient client;
                GetClient(storageInfo.StorageId, storageInfo.StorageAccessKey,
                          storageInfo.NetType, filePath, fileName,
                          out bucketName, out objectName, out client);

                //string objectKey = //($"{filePath}/{fileName}");
                //    ($"{filePath}/{fileName}?{customStyleProcessStr}");
                //.Trim(new char[] { '/' });

                GeneratePresignedUriRequest request = new GeneratePresignedUriRequest(bucketName, objectName);
                request.Process    = customStyleProcessStr;
                request.Expiration = DateTime.Now.AddHours(1);
                request.Method     = SignHttpMethod.Get;

                var presignedUri = client.GeneratePresignedUri(request);

                return(presignedUri.AbsoluteUri);
            }
        }
Example #10
0
        public async Task <string> GetUrlAsync(string objectId, MediaElementUrlType type,
                                               string format, int maxWidthHeight, int percentage)
        {
            ImageElement element = _repository.FindImageElementById(objectId);

            if (element == null)
            {
                return(string.Empty);
            }

            Storage storage = _storageService.FindStorageById(element.StorageId);

            if (storage == null)
            {
                return(string.Empty);
            }

            string url = _storageService.GetUrlByFormatSizeQuality(
                storage, element.FilePath, element.GetFileName(),
                type, format, maxWidthHeight, percentage);

            return(url);
        }
Example #11
0
 public string GetUrlByFormatSizeQuality(IStorageInfo storageInfo, MediaElementUrlType urlType, string filePath, string fileName, string format, int maxWidthHeight, int percentage)
 {
     return(GetUrlCustom(storageInfo, urlType, filePath, fileName, ""));
 }
Example #12
0
 public string GetUrlByStyle(IStorageInfo storageInfo, MediaElementUrlType urlType, string filePath, string fileName, string styleName)
 {
     return(GetUrlCustom(storageInfo, urlType, filePath, fileName, string.IsNullOrEmpty(styleName) ? "" : $"style/{styleName}"));
 }
Example #13
0
        public string GetUrlByFormatSizeQuality(Storage storage, string filePath, string fileName,
                                                MediaElementUrlType type, string format, int maxWidthHeight, int percentage)
        {
            IStorageProvider storageProvider = StorageProviderFactory.GetStorageProvider(
                _serviceProvider, storage.StorageType);

            switch (type)
            {
            case MediaElementUrlType.DownloadUrl:
            {
                return(storageProvider.GetUrlByFormatSizeQuality(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Intranet,
                        StorageAccessKey = storage.StorageAccessKey,
                        StorageId = storage.StorageId,
                        StorageHost = storage.DownloadHost,
                    }, type, filePath, fileName, format,
                           maxWidthHeight, percentage));
            }

            case MediaElementUrlType.OutputUrl:
            {
                return(storageProvider.GetUrlByFormatSizeQuality(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Internet,
                        StorageAccessKey = storage.StorageAccessKey,
                        StorageId = storage.StorageId,
                        StorageHost = storage.OutputHost,
                    }, type, filePath, fileName, format,
                           maxWidthHeight, percentage));
            }

            case MediaElementUrlType.PublishDownloadUrl:
            {
                return(storageProvider.GetUrlByFormatSizeQuality(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Intranet,
                        StorageAccessKey = storage.PublishStorageAccessKey,
                        StorageId = storage.PublishStorageId,
                        StorageHost = storage.PublishOutputHost,
                    }, type, filePath, fileName, format,
                           maxWidthHeight, percentage));
            }

            default:
            {
                return(storageProvider.GetUrlByFormatSizeQuality(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Internet,
                        StorageAccessKey = storage.PublishStorageAccessKey,
                        StorageId = storage.PublishStorageId,
                        StorageHost = storage.PublishOutputHost,
                    }, type, filePath, fileName, format,
                           maxWidthHeight, percentage));
            }
            }
        }
Example #14
0
 public string GetUrlByStyle(IStorageInfo storageInfo, MediaElementUrlType urlType, string filePath, string fileName, string styleName)
 {
     return("");
 }
Example #15
0
        /*
         * public string GetUrlByFormatSizeQuality(string storageId, string storageAccessKey,
         *  MediaElementUrlType urlType, string downloadHost, string filePath, string fileName,
         *  string format, int maxWidthHeight, int percentage)
         * {
         *  string sizeQualityString = BuildFormatSizeAndPercentage(format, maxWidthHeight, percentage);
         *
         *  return GetUrlCustom(storageId, storageAccessKey, urlType,
         *      downloadHost, filePath, fileName, sizeQualityString);
         * }
         *
         * public string GetUrlByStyle(string storageId, string storageAccessKey, MediaElementUrlType urlType,
         *  string downloadHost, string filePath, string fileName, string styleName)
         * {
         *  return GetUrlCustom(storageId, storageAccessKey, urlType,
         *      downloadHost, filePath, fileName,
         *      string.IsNullOrEmpty(styleName) ? "" : $"x-oss-process=style/{styleName}");
         * }
         *
         * public string GetUrlCustom(string storageId, string storageAccessKey, MediaElementUrlType urlType,
         *  string downloadHost, string filePath, string fileName, string customStyleProcessStr)
         * {
         *  if (string.IsNullOrEmpty(filePath))
         *  {
         *      filePath = DEFAULT_CONTAINER;
         *  }
         *  filePath = filePath.Trim('/');
         *  fileName = fileName.Trim('/');
         *
         *  if (urlType == MediaElementUrlType.PublishOutputUrl
         || urlType == MediaElementUrlType.PublishDownloadUrl)
         || {
         ||     downloadHost = downloadHost.Trim('/');
         ||     if (!string.IsNullOrEmpty(customStyleProcessStr))
         ||     {
         ||         customStyleProcessStr = "?" + customStyleProcessStr;
         ||     }
         ||     return $"{downloadHost}/{filePath}/{fileName}{customStyleProcessStr}";
         || }
         || else
         || {
         ||     StorageMode mode = StorageMode.Internal;
         ||     if (urlType == MediaElementUrlType.OutputUrl)
         ||         mode = StorageMode.External;
         ||     string bucketName, objectName;
         ||     OssClient client;
         ||     GetClient(mode, storageId, storageAccessKey, filePath, fileName,
         ||         out bucketName, out objectName, out client);
         ||
         ||     string objectKey = //($"{filePath}/{fileName}");
         ||         ($"{filePath}/{fileName}?{customStyleProcessStr}");
         ||         //.Trim(new char[] { '/' });
         ||
         ||     var presignedUri = client.GeneratePresignedUri(bucketName, objectKey,
         ||         DateTime.Now.AddHours(1), SignHttpMethod.Get);
         ||
         ||     return presignedUri.AbsoluteUri;
         || }
         ||}*/



        public string GetUrlByFormatSizeQuality(IStorageInfo storageInfo, MediaElementUrlType urlType, string filePath, string fileName, string format, int maxWidthHeight, int percentage)
        {
            string sizeQualityString = BuildFormatSizeAndPercentage(format, maxWidthHeight, percentage);

            return(GetUrlCustom(storageInfo, urlType, filePath, fileName, sizeQualityString));
        }
Example #16
0
 public string GetUrlCustom(IStorageInfo storageInfo, MediaElementUrlType urlType, string filePath, string fileName, string customStyleProcessStr)
 {
     return(storageInfo.StorageHost + "/" + storageInfo.StorageAccessKey + "/" + filePath + "/" + fileName);
 }
Example #17
0
 public string GetUrlCustom(IStorageInfo storageInfo, MediaElementUrlType urlType,
                            string filePath, string fileName, string customStyleProcessStr)
 {
     return(string.Empty);
 }