示例#1
0
 static public string ToBase64DataUrl(this byte[] item, MIMEType mime_type)
 {
     return("data:{0};base64,{1}".Inject(
                mime_type,
                item.ToBase64String()
                ));
 }
示例#2
0
        protected override bool CreateInternal(string path, string name, MIMEType mime_type, Process <Stream> process, out FileSnapshot_ById snapshot)
        {
            FileSnapshot_ById parent_file;

            if (GetStructure().TryGetFile(Filename.GetDirectory(path), out parent_file))
            {
                return(CreateInternalViaParentId(parent_file.GetId(), name, mime_type, process, out snapshot));
            }

            snapshot = null;
            return(false);
        }
示例#3
0
        // static http request proccessing logic
        public async Task <IgniteResponse> proccess(IgniteRequest request)
        {
            // get resource name from route
            String route = request.getRoute();

            String[] routePath = route.Split("/");
            if (route == "/")
            {
                logger.debug("StaticHttpProccessor@proccess | default route, servinc default page {0}", DEFAULT_PATH);
                route = DEFAULT_PATH;
            }
            else if (routePath[routePath.Length - 1].Split(".").Length == 1)
            {
                // if last path part don't have extension add default
                logger.debug("StaticHttpProccessor@proccess | no extension, adding default", DEFAULT_EXTENSION);
                route = route + DEFAULT_EXTENSION;
            }

            // reverse slashes ;)
            route = route.Replace("/", "\\");
            logger.info("StaticHttpProccessor@proccess | route {0}", route);

            // get configured working directory from configuration file
            ConfigurationService configService = await ConfigurationService.getInstance();

            IgniteConfiguration config = configService.getCoreServerConfig();
            //Console.WriteLine("StaticHttpProccessor@proccess | config {0}", config);
            String staticDataDir = config.getProperty(STATIC_DIR_PROP_NAME);

            // get file by filename
            try {
                var file = await FileSystemService.readFullFile(staticDataDir + route);

                logger.debug("StatichttpProccessor@proccess | file finded", file);
                IgniteResponse response = IgniteResponseFactory.getInstance();
                response.setBody(file);

                // set MIME TYPE
                String MIME = MIMEType.getMIMETypeByExtension(getFileExtensionByRoute(route));
                response.getHeaders()[HttpHeaders.ContentLength] = " " + file.Length.ToString();
                response.getHeaders()[HttpHeaders.ContentType]   = " " + MIME;

                return(response);
            } catch (FileNotFoundException e) {
                logger.warn("StaticHttpProccessor@proccess | no file finded by path {0}, reutning 404", staticDataDir + route);
                return(IgniteResponseFactory.getInstance(new IgniteResponseStatus(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND_MESSAGE)));
            }
        }
示例#4
0
        public override bool Write(string path, Process <Stream> process)
        {
            FILE_TYPE file;

            if (OperateOnSnapshot(path, false, s => UpdateInternal(s, process)))
            {
                return(true);
            }

            string   name      = Filename.GetFilenameWithExtension(path);
            MIMEType mime_type = MIMEType.ParseFromFilename(name);

            if (CreateInternal(path, name, mime_type, process, out file))
            {
                structure.Add(file);
                return(true);
            }

            return(false);
        }
示例#5
0
        // GET: WordDocuments/Details/5
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var wordDocument = await _context.WordDocument
                               .FirstOrDefaultAsync(m => m.Guid == id);

            if (wordDocument == null)
            {
                return(NotFound());
            }
            var cd = new System.Net.Mime.ContentDisposition
            {
                FileName = wordDocument.Title + wordDocument.FileType,
                Inline   = true
            };

            Response.Headers.Add("Content-Disposition", cd.ToString());
            return(File(wordDocument.Content, MIMEType.GetMimeType(wordDocument.FileType)));
        }
示例#6
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>Class to change the MIMEType, for the apropiate mime text.</summary>
 /// <param name="mimeEnum">The selected MIMEType</param>
 /// <returns>The mime descriptive string.</returns>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public static string extractMIMEText(MIMEType mimeEnum)
 {
     switch (mimeEnum)
     {
         case MIMEType.amr:
             return MMSContentTypes.amr;
         case MIMEType.avi:
             return MMSContentTypes.avi;
         case MIMEType.bmp:
             return MMSContentTypes.bmp;
         case MIMEType.gif:
             return MMSContentTypes.gif;
         case MIMEType.jpeg:
             return MMSContentTypes.jpeg;
         case MIMEType.midi:
             return MMSContentTypes.midi;
         case MIMEType.mp3:
             return MMSContentTypes.mp3;
         case MIMEType.mp4:
             return MMSContentTypes.mp4;
         case MIMEType.mpeg:
             return MMSContentTypes.mpeg;
         case MIMEType.png:
             return MMSContentTypes.plain;
         case MIMEType.text:
             return MMSContentTypes.plain;
         case MIMEType.v3gp:
             return MMSContentTypes.v3gp;
         case MIMEType.wav:
             return MMSContentTypes.wav;
         default:
             return null;
     }
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>Initializes a new instance of the <see cref="Attachment"/>.</summary>
 /// <param name="filePath">The attachment path.</param>
 /// <param name="mime">The attachment MIMEType.</param>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public Attachment(string filePath, MIMEType mime)
 {
     mimeType = mime;
     fileName = filePath;
 }
示例#8
0
 protected abstract bool CreateInternalViaParentId(string parent_id, string name, MIMEType mime_type, Process <Stream> process, out FileSnapshot_ById snapshot);
示例#9
0
 protected abstract bool CreateInternal(string path, string name, MIMEType mime_type, Process <Stream> process, out FILE_TYPE snapshot);
示例#10
0
        public static string MIMEToString(MIMEType type)
        {
            switch (type)
            {
            case MIMEType.ASF:
                return("video/x-ms-asf");

            case MIMEType.AVI:
                return("video/x-msvideo");

            case MIMEType.BIN:
                return("application/octet-stream");

            case MIMEType.CSS:
                return("text/css");

            case MIMEType.DLL:
                return("application/octet-stream");

            case MIMEType.DMG:
                return("application/octet-stream");

            case MIMEType.EXE:
                return("application/octet-stream");

            case MIMEType.FLV:
                return("video/x-flv");

            case MIMEType.GIF:
                return("image/gif");

            case MIMEType.HTML:
                return("text/html");

            case MIMEType.ICO:
                return("image/x-icon");

            case MIMEType.IMG:
                return("application/octet-stream");

            case MIMEType.ISO:
                return("application/octet-stream");

            case MIMEType.JPG:
                return("image/jpeg");

            case MIMEType.JS:
                return("application/x-javascript");

            case MIMEType.MP3:
                return("audio/mpeg");

            case MIMEType.MP4:
                return("video/mp4");

            case MIMEType.MPG:
                return("video/mpeg");

            case MIMEType.MSI:
                return("application/octet-stream");

            case MIMEType.PDF:
                return("application/pdf");

            case MIMEType.PNG:
                return("image/png");

            case MIMEType.RAR:
                return("application/x-rar-compressed");

            case MIMEType.SWF:
                return("application/x-shockwave-flash");

            case MIMEType.TXT:
                return("text/plain");

            case MIMEType.WMV:
                return("video/x-ms-wmv");

            case MIMEType.XML:
                return("text/xml");

            case MIMEType.ZIP:
                return("application/zip");

            default:
                return(null);
            }
        }