user7066088
user7066088

Reputation:

How can I getting rid from base64string in the URL

I am retrieving image from database like this:

public ViewResult Details(int id = 0)
{
    vm.ImageToShow = Convert.ToBase64String(model.Picture)
    return View(vm);
}

The Picture definition:

public byte[] Picture { get; set; }

And I am showing it in the View like this:

@Html.Raw("<img src=\"data:image/jpeg;base64," + Model.ImageToShow + "\" 
onclick='javascript: window.open(\"data:image/jpeg;base64," + Model.ImageToShow + "\")'/>")

When I click on it. it opens a new tab and show image but the URL is showing all base64 string like data:image/jpeg;base64,iVBORw0KGg...... How can I getting rid of this and show a short url with image name or anything else?

Upvotes: 0

Views: 57

Answers (1)

Akash Kava
Akash Kava

Reputation: 39916

public ViewResult Details(int id = 0)
{
    //vm.ImageToShow = Convert.ToBase64String(model.Picture)
    vm.ID = id;
    return View(vm);
}

public FileResult Image(int id = 0)
{
    ..
    return File(model.Picture,"image/jpeg");
}


@Html.Raw("<img src=\"image?id=" + Model.ID + "\" 
onclick='javascript: window.open(\"image?id=," + Model.ID + "\")'/>")

Upvotes: 1

Related Questions