.
JavaScript
In this example, we use the input form field to upload an image. When you select an image on your computer, the image will be displayed on the page:
Document. getElementById ('upload-file '). addEventListener ('change', function () {var file; var destination = document. getElementById ('destination'); destination. innerHTML = ''; // loop the multiple objects selected by the user for (var x = 0,
front end, it is not necessary to theoretically limit the size of the picture.
Second, the picture front-end JS compression and upload function experienceSpecially made a picture front-end compression and upload the full demo, you can ruthlessly click here: Use canvas to compress images in the front and upload the demoEnter the demo to see a plain File entry box:Ah, no, it should be this picture:Click on the
JavaScript uses the HTML file API to read files, noting that "read" is read-only and does not take the initiative to get a list of files from the host on which the browser resides. HTML5 in Fileapi mainly have FileUpload, File,FileList,fileerror,Blob,filereader,datatransfer. Here the main test file. It is therefore ne
, the Reader.onload event is called. Here, I also input the reading results into the console, such as the console output of the Base64 code (part) is: Light a picture there is so much data, specifically I did not study, but I know that the larger the picture, the larger the amount of data. But all the pictures are similar in the previous paragraph. such as the red callout part, is "data:image/jpeg;base64,", then is the body content of the picture. What's the use of this body of content? We can w
filereader provided by HTML5 to read files from the client. In Chrome, you can use the formdata object as the value of the send method parameter of the XMLHttpRequest instance. You can also use the window. btoa method to convert the file into a base64 encoded text stream and use it as the parameter value of the send method. If btoa is used, the actual number of
Interface style I was referring to a foreign Photo album website, the change is not big, just to convert the birds into Chinese, as well as the upload style has also been changed, the reason for this is that I can easily do the extension, it supports 3 ways to add pictures, a drag-and-drop upload, a general choice of file upload, The other thing is to add a Web image. It is very clever to integrate three ki
I just got into touch with the concept of an inline image. Even if I encode the image file into base64, the following code is an inline problem.
Http requests can be reduced, but cross-origin cache is not allowed!
How to convert an image to base64 online
If javascript alone is a permission issue, javascript does not allow operations on local file files or fold
Domstring object.
Properties
An object that sets some of the properties of a Blob object
For example, the following code can create an XML-formatted data:
var afileparts = [' var omyblob = new Blob (afileparts, {"type": "Text/xml"}); The Blob
1.2 Canvas.toblob method
The Htmlcanvaselement.toblob () method creates a Blob object to display the picture on the canvas, which can be cached or saved locally and determined by the user's proxy. If not specifically, the type of the picture defaults
File upload is now becoming more and more common, all social networking sites, media sites, such as Youku video, micro-blog, etc., all provide upload pictures, upload video and other functions. But in the past, web programmers know that uploading files with HTML forms can be a hassle, especially if you want to know some of the properties of a user's uploaded file, and you'll have to wait until it's uploaded
Interface style I was referring to a foreign album website, change is not big, just convert the birds into Chinese, and upload the style also made changes, the reason for this choice is that I am easy to do extension, it supports 3 ways to add pictures, a drag and drop upload, a general selection file upload, The other is to add network pictures. It is very clever to integrate three kinds of upload mode, an
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.