I am using ekko-lightbox to display image in popup, images gets displayed as expected in thumbnail however when i click on image it opens model and displays junk characters.
Here is the application url which download image from database but open clicking the thimlnail it displays junk characters. http://localhost:8080/insignia/downloadImage.html?piid=1
And below link works fine even in model popup also. https://lh3.googleusercontent.com/-kgMllZrb20s/T0oJD2nFklI/AAAAAAAAQyg/pnMfqLAGNJs/s1024/IMG_0736%2520-%2520original.jpg
Below is my html code to display and download image gallery and preview image.
<c:forEach var="item" items="${form.patient.patientImages }" varStatus="status">
<div class="container">
<div class="row">
<div class="col-md-offset-1 col-md-10">
<div class="row">
<a href="http://localhost:8080/insignia/downloadImage.html?piid=1" data-toggle="lightbox" data-gallery="imagesizes" class="col-sm-3">
<img src="http://localhost:8080/insignia/downloadImage.html?piid=1" class="img-responsive">
</a>
<a href="https://lh3.googleusercontent.com/-kgMllZrb20s/T0oJD2nFklI/AAAAAAAAQyg/pnMfqLAGNJs/s1024/IMG_0736%2520-%2520original.jpg" data-toggle="lightbox" data-gallery="imagesizes" class="col-sm-3">
<img src="https://lh3.googleusercontent.com/-kgMllZrb20s/T0oJD2nFklI/AAAAAAAAQyg/pnMfqLAGNJs/s128/IMG_0736%20-%20original.jpg" class="img-responsive">
</a>
<a href="https://lh3.googleusercontent.com/-kgMllZrb20s/T0oJD2nFklI/AAAAAAAAQyg/pnMfqLAGNJs/s1024/IMG_0736%2520-%2520original.jpg" data-toggle="lightbox" data-gallery="imagesizes" class="col-sm-3">
<img src="https://lh3.googleusercontent.com/-kgMllZrb20s/T0oJD2nFklI/AAAAAAAAQyg/pnMfqLAGNJs/s1024/IMG_0736%2520-%2520original.jpg" class="img-responsive">
</a>
</div>
</div>
</div>
</div>
</c:forEach>
<script type="text/javascript">
$(document).ready(function ($) {
// delegate calls to data-toggle="lightbox"
$(document).delegate('*[data-toggle="lightbox"]:not([data-gallery="navigateTo"])', 'click', function(event) {
event.preventDefault();
return $(this).ekkoLightbox({
onShown: function() {
if (window.console) {
return console.log('Checking our the events huh?');
}
},
onNavigate: function(direction, itemIndex) {
if (window.console) {
return console.log('Navigating '+direction+'. Current item: '+itemIndex);
}
}
});
});
//Programatically call
$('#open-image').click(function (e) {
e.preventDefault();
$(this).ekkoLightbox();
});
$('#open-youtube').click(function (e) {
e.preventDefault();
$(this).ekkoLightbox();
});
$(document).delegate('*[data-gallery="navigateTo"]', 'click', function(event) {
event.preventDefault();
return $(this).ekkoLightbox({
onShown: function() {
var a = this.modal_content.find('.modal-footer a');
if(a.length > 0) {
a.click(function(e) {
e.preventDefault();
this.navigateTo(2);
}.bind(this));
}
}
});
});
});
</script>
Below is my spring controller code to download image from database.
@RequestMapping(value = "downloadImage.html", method = RequestMethod.GET)
public void downloadImage(@Valid @ModelAttribute("form") PatientForm form, BindingResult result, Model model, HttpServletResponse response) throws IOException {
if (request.getParameter("piid") != null) {
Long patientImageId = Long.valueOf(request.getParameter("piid"));
response.setContentType("image/jpg");
PatientImage patientImage = patientService.findImageById(patientImageId);
OutputStream outputStream = null;
try {
outputStream = response.getOutputStream();
outputStream.write(patientImage.getActualImage());
} catch (IOException e) {
logger.error(e.getMessage(), e);
e.printStackTrace();
} finally {
outputStream.flush();
outputStream.close();
}
}
}
Can somebody help me resolve this issue?