I want the file that I uploaded in the documentUploadProvinceLevels database table to be able to be download.I implemented the file upload part, but I don t know what to do for downloading. please help me
Upload code:
public bool UploadAvatarProvinceDB(IFormFile file, RegisterViewModel document)
{
if (file != null)
{
if (file.Length > 0)
{
int department = 1;
document.uploadDate = DateTime.Now;
document.fileName = "no-document";
document.description = "ثبت تصویر پرسنل";
var docName = Path.GetFileName(file.FileName);
var fileExtension = Path.GetExtension(docName);
var newFileName = String.Concat(document.nationalCode, fileExtension);
var objfiles = new DocumentUploadProvinceLevel()
{
id = 0,
fileName = newFileName,
uploadDate = DateTime.Now,
title = "تصویر پرسنل",
fileFormat = fileExtension,
userId = document.nationalCode,
description = document.description,
department = department,
IsDelete=false
};
using (var target = new MemoryStream())
{
file.CopyTo(target);
objfiles.dataBytes = target.ToArray();
}
_context.documentUploadProvinceLevels.Add(objfiles);
_context.SaveChanges();
return true;
}
}
return false;
}