Answer the question
In order to leave comments, you need to log in
Is it possible to upload files to the client without using the server?
Hello. Interested in whether it is possible to upload files to the page without using the server and, accordingly, server-side Java? I have a small web application (for myself and a cat), I want to implement the loading of a picture (and preferably several), so that when the change event occurs (that is, when the user clicks on the input with the file type and selects the image), its loading starts and it is displayed on the page in the required block, now a static image is used which does not change during the change event. I am not at all friendly with the server side of web applications, but I write a little in js, so I want to get by with only html and js tools. Please, prompt approximate implementation or where to esteem.
Answer the question
In order to leave comments, you need to log in
So it won't work?)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>load foto</title>
</head>
<body>
<form id="form1" runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
</script>
</body>
</html>
If you need to display an image without uploading it to the server, look towards FileReader. Also, I think you can save the image on the client in localstorage as base64 encoding.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question