private void ListFiles(string path, string type) { var isFirstItem = true; var files = GetFiles(GetRelativePath(path), type); Response.Write("["); foreach (var file in files) { if (isFirstItem) { isFirstItem = false; } else { Response.Write(","); } var url = _fileSystem.GetPublicUrl(file.Path); var size = file.Dimensions; Response.Write("{"); Response.Write("\"p\":\"" + url + "\""); Response.Write(",\"t\":\"" + file.LastUpdated.ToUnixTime().ToString() + "\""); Response.Write(",\"m\":\"" + MimeTypes.MapNameToMimeType(file.Name) + "\""); Response.Write(",\"s\":\"" + file.Size.ToString() + "\""); Response.Write(",\"w\":\"" + size.Width.ToString() + "\""); Response.Write(",\"h\":\"" + size.Height.ToString() + "\""); Response.Write("}"); } Response.Write("]"); }
public virtual string GetPublicUrl(string imagePath) { if (imagePath.IsEmpty()) { return(null); } return(_fileSystem.GetPublicUrl(BuildPath(imagePath), true).EmptyNull()); }
private void ListFiles(string path, string type) { var files = GetFiles(GetRelativePath(path), type); var result = files.Select(x => new { p = _fileSystem.GetPublicUrl(x), t = x.LastUpdated.ToUnixTime().ToString(), m = GetMimeType(x), s = x.Size.ToString(), w = x.Dimensions.Width.ToString(), h = x.Dimensions.Height.ToString() }).ToArray(); Write(result); }
public virtual string GetImageUrl(string imagePath, string storeLocation = null) { if (imagePath.IsEmpty()) { return(null); } var publicUrl = _fileSystem.GetPublicUrl(BuildPath(imagePath)).EmptyNull(); if (publicUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || publicUrl.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { // absolute url return(publicUrl); } var root = storeLocation; if (root.IsEmpty()) { var cdnUrl = _storeContext.CurrentStore.ContentDeliveryNetwork; if (cdnUrl.HasValue() && !_httpContext.IsDebuggingEnabled && !_httpContext.Request.IsLocal) { root = cdnUrl; } } if (root.IsEmpty()) { // relative url must start with a slash return(publicUrl.EnsureStartsWith("/")); } if (HostingEnvironment.IsHosted) { // strip out app path from public url if needed but do not strip away leading slash from publicUrl var appPath = HostingEnvironment.ApplicationVirtualPath.EmptyNull(); if (appPath.Length > 0 && appPath != "/") { publicUrl = publicUrl.Substring(appPath.Length + 1); } } return(root.TrimEnd('/', '\\') + publicUrl.EnsureStartsWith("/")); }
private void ListFiles(string path, string type) { var isFirstItem = true; var width = 0; var height = 0; var files = GetFiles(GetRelativePath(path), type); Response.Write("["); foreach (var file in files) { try { GetImageSize(file.Path, out width, out height); } catch { } if (isFirstItem) { isFirstItem = false; } else { Response.Write(","); } var url = _fileSystem.GetPublicUrl(file.Path); Response.Write("{"); Response.Write("\"p\":\"" + url + "\""); Response.Write(",\"t\":\"" + file.LastUpdated.ToUnixTime().ToString() + "\""); Response.Write(",\"s\":\"" + file.Size.ToString() + "\""); Response.Write(",\"w\":\"" + width.ToString() + "\""); Response.Write(",\"h\":\"" + height.ToString() + "\""); Response.Write("}"); } Response.Write("]"); }
public string GetPublicUrl(MediaFile mediaFile) { return(_fileSystem.GetPublicUrl(GetPath(mediaFile), true)); }
public async Task <ActionResult> File(string path) { string name = null; string mime = null; if (path.IsEmpty()) { return(NotFound(null)); } var tenantPrefix = DataSettings.Current.TenantName + "/"; if (path.StartsWith(tenantPrefix)) { // V3.0.x comapt: in previous versions the file path // contained the tenant name. Strip it out. path = path.Substring(tenantPrefix.Length); } name = Path.GetFileName(path); name.SplitToPair(out var nameWithoutExtension, out var extension, ".", true); mime = MimeTypes.MapNameToMimeType(name); if (nameWithoutExtension.IsEmpty() || extension.IsEmpty()) { return(NotFound(mime ?? "text/html")); } extension = extension.ToLower(); var file = _mediaFileSystem.GetFile(path); if (!file.Exists) { return(NotFound(mime)); } var query = CreateImageQuery(mime, extension); var isProcessableImage = query.NeedsProcessing(true) && _imageProcessor.IsSupportedImage(file.Name); if (isProcessableImage) { var cachedImage = _imageCache.Get(file, query); return(await HandleImageAsync( query, cachedImage, nameWithoutExtension, mime, extension, getSourceBufferAsync)); } // It's no image... proceed with standard stuff... if (Request.HttpMethod == "HEAD") { return(new HttpStatusCodeResult(200)); } if (_mediaFileSystem.IsCloudStorage && !_streamRemoteMedia) { // Redirect to existing remote file Response.ContentType = mime; return(Redirect(_mediaFileSystem.GetPublicUrl(path, true))); } else { // Open existing stream return(new CachedFileResult(file, mime)); } async Task <byte[]> getSourceBufferAsync(string prevMime) { return(await file.OpenRead().ToByteArrayAsync()); } }