c# - How to encode an image to display it in browser -


i have alot of images saved in folder on server side, database has url of each 1 , client cannot open images directly because of permisson. problem how can encode image display in browser server?

this code have in action result search image:

public fileresult searchimage() {      var path = @"\\jesus-pc\frontera\imagenes\singnos distintivos\0\80hp23891268272.tif";     var img1 = system.io.file.readallbytes(path);      return file(im1, "image/jpg"); } 

the image exists displayed:

image not loading

i tried convert.tobase64string(img1) got error:

the server responded status of 414 (request-uri long) 

what doing wrong?

update:

my bad did not write whole code of i'm doing.

the last part did not mentioned im using ajax call image.

when user sends request information, there link open modal box. inside modal box image must displayed image loaded using ajax because page should not reloaded. image requested ajax. here code:

$(".doc").dblclick(function () {   $.ajax({     url: "mainpage/searchimage",     data: "",     type: "post",     success: function (data) {         modalwindow.open();         document.getelementbyid("img_1").src = data;     }  }) 

consider using filestreamresult instead of fileresult. should solve issue. code shou like:

public filestreamresult searchimage() {      var path =         @"\\jesus-pc\frontera\imagenes\singnos distintivos\0\80hp23891268272.tif";     var filestream = new filestream(path, filemode.open, fileaccess.read);     return new filestreamresult(filestream, "image/jpeg"); } 

another thing takes attention mime-type specified. in filename it's tif in code it's jpeg.

update

why using ajax this? can instead:

$('#img_1').attr('src', 'mainpage/searchimage'); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -