private static void GetEmbeddedResource(string resourceName, ref byte[] content, ref string contentType, ref string name, ref bool cacheable)
        {
            if (string.IsNullOrEmpty(resourceName))
            {
                return;
            }

            string[] parts = resourceName.Split('?');
            resourceName = parts[0];

            name        = GetResourceFileName(resourceName);
            contentType = MimeType.GetMimeType(resourceName);
            cacheable   = true;

            resourceName = ResourceVirtualPathProvider.ManifestResourceNamePrefix + "." + resourceName;

            if (resourceName.EndsWith(BootstrapIconsStyleSheet, StringComparison.OrdinalIgnoreCase))
            {
                content = Encoding.UTF8.GetBytes(ProcessBootstrapIconsStyleSheet(GetManifestResourceString(resourceName)));
            }
            else
            {
                content = GetManifestResourceBytes(resourceName);
            }
        }
        private static BlobHttpHeaders CreateBlobHttpHeaders(string contentType, string fileName)
        {
            if (MimeType.IsDefaultOrEmpty(contentType))
            {
                contentType = MimeType.GetMimeType(fileName);
            }

            var blobHttpHeaders = new BlobHttpHeaders
            {
                ContentType  = contentType,
                CacheControl = Settings.ClientCacheControl
            };

            if (contentType.In(MimeType.Html))
            {
                blobHttpHeaders.ContentDisposition = "attachment";
            }

            return(blobHttpHeaders);
        }
        public string UploadFileFromUrl(string fileUrl, FileContentTypeValidator validator)
        {
            if (!string.IsNullOrEmpty(fileUrl))
            {
                string fileName    = null;
                string contentType = null;
                byte[] buffer      = null;

                if (fileUrl.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) // data:[<media type[;charset=utf-8]>][;base64],<data>
                {
                    string[] parts  = fileUrl.Split(',');
                    string[] parts2 = parts[0].Split(':')[1].Split(';');

                    if (Array.IndexOf <string>(parts2, "base64") > -1)
                    {
                        buffer = Convert.FromBase64String(parts[1]);
                    }
                    else if (parts.Length > 1)
                    {
                        string data = parts[1];

                        if (!string.IsNullOrEmpty(data))
                        {
                            string charset = Array.Find <string>(parts2, x => x.StartsWith("charset=", StringComparison.OrdinalIgnoreCase));
                            if (!string.IsNullOrEmpty(charset))
                            {
                                charset = charset.Split('=')[1];
                                if (!string.IsNullOrEmpty(charset))
                                {
                                    try
                                    {
                                        Encoding encoding = Encoding.GetEncoding(charset);

                                        data = HttpUtility.UrlDecode(data, encoding);
                                    }
                                    catch (ArgumentException) { }
                                }
                            }
                        }

                        buffer = Encoding.UTF8.GetBytes(data);
                    }

                    contentType = parts2[0];
                    fileName    = Guid.NewGuid().ToString("N").Substring(0, 12) + MimeType.GetExtension(contentType);
                }
                else if (fileUrl.StartsWith(Uri.UriSchemeHttp + Uri.SchemeDelimiter, StringComparison.OrdinalIgnoreCase) ||
                         fileUrl.StartsWith(Uri.UriSchemeHttps + Uri.SchemeDelimiter, StringComparison.OrdinalIgnoreCase))
                {
                    fileName    = Path.GetFileName(fileUrl.Split('?')[0]);
                    contentType = MimeType.GetMimeType(fileName);

                    string responseContentType = null;

                    using (WebClient webClient = new WebClient())
                    {
                        buffer = webClient.DownloadData(fileUrl);

                        if (webClient.ResponseHeaders != null)
                        {
                            responseContentType = webClient.ResponseHeaders["Content-Type"];
                        }
                    }

                    if (!string.IsNullOrEmpty(responseContentType) && string.Compare(responseContentType, contentType, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        fileName    = Path.GetFileNameWithoutExtension(fileName) + MimeType.GetExtension(responseContentType);
                        contentType = responseContentType;
                    }
                }

                if (buffer != null)
                {
                    if (validator != null)
                    {
                        if (!validator.Invoke(contentType))
                        {
                            throw new InvalidDataException(string.Format(CultureInfo.InvariantCulture, Resources.FileManager_InvalidContentType, contentType));
                        }
                    }

                    return(UploadFile(fileName, contentType, buffer));
                }
            }

            return(null);
        }