Reputation: 10115
Add file in the static folder and save an image in the static folder.
Save base64 image in the Dot net core project.
Upvotes: 2
Views: 12745
Reputation: 10115
public class EventMastersController : Controller
{
private IHostingEnvironment _env;
public EventMastersController(IHostingEnvironment env)
{
_env = env;
}
public void AddFolderAndImage()
{
var webRoot = _env.WebRootPath;
var PathWithFolderName = System.IO.Path.Combine(webRoot, "MyFolder");
if (!Directory.Exists(PathWithFolderName))
{
// Try to create the directory.
DirectoryInfo di = Directory.CreateDirectory(PathWithFolderName);
string Base64String = eventMaster.BannerImage.Replace("data:image/png;base64,", "");
byte[] bytes = Convert.FromBase64String(Base64String);
Image image;
using (MemoryStream ms = new MemoryStream(bytes))
{
image = Image.FromStream(ms);
}
image.Save(PathWithFolderName + "/ImageName.png");
}
}
Upvotes: 2