Failure to display images on the http page - c#

I am uploading png pictures in asp.net mvc. And I save their address in the database. I get a 404 error while displaying some images on the http page. Whereas on https, the images are loaded and the images are exist.
This problem exists only for png images or a specific folder. This is not a problem with jpeg images.
please help me
<img class="default-img" src="#item.Image" alt="">
item.Image="/images/Post/166362.png"

Related

Have a question concerning Http and Https and Images

When I used Nextjs Client with http and C# Api with Http, I can make the client show the images which is saved in the virtual directory. But when I upgrade my nextjs to Https, the images do not show anymore. As I see in F12 in client, all of my image path was converted to have https. Eg: http://domain.info/images/filename.jpg was converted to https://domain.info/images/filename.jpg
I use IIS Window Server to upload my code.
My image code:
{logoData ?
<div className="logo">
<img className="img-fluid" src=
{BaseGatewayImage + logoData.imagePath} alt="Newsprk" data-lazy-src=
{BaseGatewayImage + logoData.imagePath} />
</div> : <></>}
this is the images after https:
Images after https
Can some one help me with this case? Do I have to upgrade my api to https?

show image from another server HTML

I have this image URL i got from database.
\\Imagepath\ImageFolder\image.png
but i need to put in a img tag in html to show the image in the page, i try to do this way
<img src='\\Imagepath\ImageFolder\image.png'/>
but the page adds the default url for localhost, ie.
http://localhost:1234/\\Imagepath\ImageFolder\image.png
I need your helpfor trying to get the image from that server URL.
I have a lot of images around 6,200 so is not an option to download, i'm show the images in a table.
NOTE: i know the img tag not accept the URL like i have, but maybe you have an idea to do in ASP.NET, i apretiate your help.
NOTE 2:i'm using ASP.NET MVC.
Paths starting with \\ are UNC paths, they are not URLs. In a browser, you have to use a URL to load an image.
The browser is assuming you've tried to specify a relative URL, and is attempting to add the current URL by default in order to fully qualify it and then make a request to it to get the image.
You need to map the path to a virtual directory in your webserver and then point the image's src property at the URL of that virtual directory.
Alternatively, if that's not a workable solution you could write an MVC action method which takes the name of the image file as a parameter and then loads the image from the UNC path in the background and returns the data in a binary response to the browser.

How to return image without downloading Azure Blob Storage

I have some images in blob storage and I want to get this image through url publica. However when passing the url in the browser the image is downloaded and not opened.
For example:
https://account.blob.core.windows.net/avatares/folder/file.png
Download the image.
I want a way to do the same as amazon S3, when I ask Url she already opens the image in the browser.
example: https://s3.amazonaws.com/account/avatar/pequeno/file.png

File management for profile pictures

I'm bulding an ASP.NET website where the users can upload their profile picture. I store these images under the App_Data folder and the file paths in the Users table.
So, the question is how should I update the user's profile picture? I mean, what happens if I overwrite the previous file and at the same time a request arrives to get the picture. Should I have some concurrency management?
My best solution is generating a file name for the new image(the user record in the database would be updated with this new path as well) and store the old path somewhere else, in order to delete it later.
Is this a good idea?
What I generally do in my case.
Creates a folder in my project with path ~/uploads/images. Here images is my concerned folder which is under uploads and uploads is in root.
While saving image path to db i use simple
var dbpath=
string.Format("~/Uploads/Images/{0}",Guid.NewGuid().ToString().Replace("-",string.Empty));
And from file upload control Fu.SaveAs(Server.MapPath(dbPath));
If you want to display image over the page from database, either you can use
<asp:Image runat="server" id="immm"></asp:Image> , from code behind imm.ImageUrl = dt.Rows[0]["ImagePath"].ToString"
2.If its inside grid/repeater, use simply <asp:Image runat="server" id="immm" ImageUrl='<%#Eval("ImagePath")%'></asp:Image>
No need to generate new file names. There's a very smart solution.
Alter your Users table and add a Uploadversion field. And overwrite the same file with uploaded file and just increase a upload version field in your Users table.
When your client requests the file, send the path with this version. Client may add this version as fake querystring to src path of your img element.
<img src="/[image_route]?[version]" />
For ex:
<img src="/images/john_doe/photo?16" />

Get real type of file that user want to upload

in my ASP.Net MVC 3 application I have uploading images logic. How can I find out is some file that user try to upload realy an image? I need to check it before uploading , on client side
If you use:
Image.FromStream(stream)
it will throw an ArgumentException if it is not a valid image.

Categories