public override void DoGet(HttpRequest req, HttpResponse res)
        {
            String path     = req.GetQueryParameter("path");
            String fileName = Utilities.GetFileName(path);
            Stream stream   = FileManager.DownloadFile(path);

            res.Headers.Add("Content-Type", MIMETypes.GetContentType(path));
            res.Headers.Add("Content-Disposition", $"inline; filename = \"{fileName}\"");
            res.Headers.Add("Content-Length", stream.Length.ToString());
            res.Content = stream;
        }
        public static string GetMimeTypeForFile(string fileName)
        {
            var fileExtension = System.IO.Path.GetExtension(fileName);
            var mimeType      = "application/unknown";

            if (fileExtension != null)
            {
                mimeType = MIMETypes.ContainsKey(fileExtension) ? MIMETypes[fileExtension] : GetMimeTypeForFileFromRegistry(fileName);
            }
            return(mimeType);
        }
Ejemplo n.º 3
0
        // Get MIME types
        public static string GetContentType(string FilePath)
        {
            string Extension =
                System.IO.Path.GetExtension(FilePath).ToLowerInvariant();

            if (MIMETypes.ContainsKey(Extension))
            {
                return(MIMETypes[Extension]);
            }
            else
            {
                return("application/octet-stream");
            }
        }
Ejemplo n.º 4
0
        public void Process(HttpRequest req, HttpResponse res)
        {
            res.Headers.Add("Location", _path);
            res.Headers.Add("Content-Type", MIMETypes.GetContentType(_path));

            Stream content;

            try
            {
                content = new StreamReader((_root + "/" + _path)).BaseStream;
            }
            catch
            {
                content = new MemoryStream();
            }
            res.Headers.Add("Content-Length", content.Length.ToString());
            res.Content = content;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the URL to a document. MimeType is used to assemble a URL that is compatible with Guidewire
        /// </summary>
        /// <param name="documentId">The document ID to get the URL for</param>
        /// <param name="mimeType">The MimeType as it is represented in ClaimCenter</param>
        /// <returns></returns>
        public GetDocumentUrlResult GetDocumentUrl(string documentId, string mimeType)
        {
            GetDocumentUrlResult result = GetDocumentUrl(documentId);

            if (result.Success)
            {
                // Check the extension of the document, and do additional processing if the extension is missing, contains a space or doesn't match a known extension from ClaimCenter
                string currentExtension = Path.GetExtension(result.DocumentUrl);
                using (MIMETypes mimeTypes = new MIMETypes())
                {
                    if (string.IsNullOrEmpty(currentExtension) || currentExtension.Contains(" "))
                    {
                        //Document doesn't have an extension.  Resolve this before attempting to access it.
                        result.DocumentUrl = Util.ResolveMissingExtension(result.DocumentUrl, mimeType);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Uses the MIMETypes class to match extensions to known MimeTypes from Guidewire. If changes are made to the document name, the new document URL is returned
        /// </summary>
        /// <param name="documentUrl">The URL of the document to resolve</param>
        /// <param name="mimeType">The MimeType as it exists in ClaimCenter</param>
        /// <returns></returns>
        public static String ResolveMissingExtension(string documentUrl, string mimeType)
        {
            List <string> extension = new List <string>();

            //if (Path.HasExtension(newDocUrl)) return newDocUrl;

            // Get the list of known mime types/extensions
            using (MIMETypes mimetypes = new MIMETypes())
            {
                if (mimetypes.ContainsMimetype(mimeType))
                {
                    extension = mimetypes.ExtensionMapping[mimeType];
                }
            }

            //TODO - Add logic to update the document name in the Content Server so that this doesn't happen again.

            return(documentUrl + extension.First());
        }