GerryMM88
GerryMM88

Reputation: 191

Showing a image with random filename and type in page

I have used this tutorial https://learn.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-6.0 to upload images from user to my own location. This is working fine, and when the user uploads the files I get something like "friIjfdls.m4s". It also works fine downloading them.

Just to give a short explanation of the process:

So when the user wants do download it I retrieve the image and the correct name (from db) and "merge" them.

But now I came out for a problem because I also want to show the images on my page. Is that possible? So I cant use the same process as "download file" because that makes the server to a lot of stuff before sending it to the user and it automatically starts downloading. But I just want to show the image as a static(?) image on the page. How can I do that?

Upvotes: 1

Views: 214

Answers (1)

GerryMM88
GerryMM88

Reputation: 191

So I ended up doing it this way:

        FileStream fileStream = ResourcesRepository.GetFileByUrl(imagePath);

        byte[] bytes = new byte[fileStream.Length];
        fileStream.Read(bytes, 0, (int)fileStream.Length);
        this.ImageBase64 = Convert.ToBase64String(bytes);

And this worked. Thank you @J.Salas for the direction.

Upvotes: 1

Related Questions