[Route("GetPics")] [HttpGet] public IActionResult GetPics() { //List<Files> images = new List<Files>(); ////Set the Image Folder Path. //string path = HttpContext.Current.Server.MapPath("~/Images/"); Files f = new Files(); var data = from i in _context.Files select i.DataFiles; return Ok(data); }
<script type="text/javascript"> $("#btnShow").click(function () { var options = {}; options.url = "/api/Pics/GetPics"; options.type = "GET"; options.dataType = "json"; options.contentType = "application/json"; options.success = function (results) { $("#imgContainer").empty(); for (var i = 0; i < results.length; i++) { debugger; //alert(results); //$("#imgContainer").html(results); $("#imgContainer").append("<img src='" + "api/Pics/GetPics/" + results[i].type + "' /> <br />"); //$('#imgContainer').attr('src', results[i].target.result); } }; options.error = function (err) { alert(err.statusText); }; $.ajax(options); }); </script>
[Table("Files")] public class Files { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int DocumentId { get; set; } [MaxLength(100)] public string Name { get; set; } [MaxLength(100)] public string FileType { get; set; } [MaxLength] public byte[] DataFiles { get; set; } public DateTime? CreatedOn { get; set; } }
CREATE TABLE [dbo].[Files] ( [DocumentId] INT IDENTITY (1, 1) NOT NULL, [Name] VARCHAR (100) NULL, [FileType] VARCHAR (100) NULL, [DataFiles] VARBINARY (MAX) NULL, [CreatedOn] DATETIME NULL, CONSTRAINT [PK_Files] PRIMARY KEY CLUSTERED ([DocumentId] ASC) );
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)