Beispiel #1
0
        /// <summary>
        /// Returns a URL to the file with corresponding filename
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public string GetUrlByFilename(string fileName = "ppap.png")
        {
            FileObjectModels file = db.FilesObjects.Single(f => f.Filename == fileName);

            if (file != null)
            {
                return(string.Format("data:{0};base64,{1}", file.ContentType, Convert.ToBase64String(file.Data)));
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Creates and returns a new FileObjectModel based on input
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="bytes"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        private FileObjectModels CreateModel(string fileName, byte[] bytes, string contentType)
        {
            //Create relevant model
            FileObjectModels model = new FileObjectModels();

            model.Filename    = fileName;
            model.Data        = bytes;
            model.ContentType = contentType;
            return(model);
        }
Beispiel #3
0
        /// <summary>
        /// Generates a URL to the file with corresponding filename
        /// </summary>
        /// <param name="fileName">
        /// Name of the file
        /// </param>
        /// <returns>
        /// Returns a string url
        /// </returns>
        public string GenerateFileUrl(string fileName)
        {
            FileObjectModels file = _context.FilesObjects.SingleOrDefault(o => o.Filename == fileName);

            return((file != null) ? string.Format("data:{0};base64,{1}", file.ContentType, Convert.ToBase64String(file.Data)) : null);
        }