Hi everyone I have an issue I am making API on .net core when I call data in this there is filed image which return image path, I want to convert it into byte64, when I converted then there is a lot of time to give response below is my code.
I want a response in no time,
- var data = await Task.Run(() => context.GetStoreProc.FromSqlRaw("EXECUTE dbo.Nstp_GetTeamBy_ID {0}", ManagerID).Select(x => new TeamManagerResponse
- {
- DepartmentName = x.DepartmentName,
- DesignationDesc = x.DesignationDesc,
- EmailAdd = x.EmailAdd,
- EmpImg = DataHelper.ConvertImageToByteArray(x.EmpImg), // below is this method
- EmpName = x.EmpName
- }).ToListAsync());
- return data;
- public static string ConvertImageToByteArray(string Image_Path)
- {
- string imgPathFinal = "";
- var imgPath = System.Reflection.Assembly.GetEntryAssembly().Location;
- int location = imgPath.LastIndexOf("\\bin");
- imgPathFinal = imgPath.Substring(0, location) + Image_Path;
- byte[] imageByteArray = null;
- if (File.Exists(imgPathFinal))
- {
-
- FileStream fileStream = new FileStream(imgPathFinal, FileMode.Open, FileAccess.Read);
- using (BinaryReader reader = new BinaryReader(fileStream))
- {
- imageByteArray = new byte[reader.BaseStream.Length];
- for (int i = 0; i < reader.BaseStream.Length; i++)
- imageByteArray[i] = reader.ReadByte();
- }
- return Convert.ToBase64String(imageByteArray, 0, imageByteArray.Length);
- }
- else
- {
- return imgPathFinal;
- }
-
- }
please help me