//----------------------------------// /// <summary> /// Initialize a web resource. /// </summary> public WebResource(HttpSite site, string path, string mime = null) { _lock = new LockShared(); // persist the local path Path = path; // does the path indicate a web resource? if (Fs.IsWebPath(Path)) { // persist the path FullPath = Path; } else { // persist the path FullPath = Fs.Combine(site.Path, Path); } _compression = System.Net.DecompressionMethods.None; // get the web resource extension if set MimeType = mime ?? Mime.GetType(Fs.GetExtension(FullPath)); // the resource must be loaded to begin with _reset = true; }
/// <summary> /// Send the file at the specified local path. /// </summary> public void SendLocal(string path, HttpSendOptions options = null, IAction onSent = null) { Log.Info("Sending local file '" + path + "' bytes to client " + this + "."); // get the extension from the path string extension; int extensionIndex = path.LastIndexOf(Chars.Stop); if (extensionIndex == -1) { extension = null; } else { extension = path.Substring(extensionIndex); } if (options == null) { options = new HttpSendOptions { ContentType = Mime.GetType(extension) } } ; // open a file stream to the resource var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); // start sending the file StartSendStream(fileStream, (int)fileStream.Length, options, onSent); }
private IActionResult GetFile(FileInfo file, string dataStream = null) { if (file == null) { return(NotFound()); } if (dataStream != null && file.Exists && file.AlternateDataStreamExists(dataStream)) { return(File(file.GetAlternateDataStream(dataStream, FileMode.Open).OpenRead(), Mime.GetType(dataStream))); } if (dataStream == null && file.Exists) { return(PhysicalFile(file.FullName, Mime.GetType(file.Name))); } return(NotFound()); }