JQ select a picture url base64-encoded transfer

HTML

<input type='file' class='upload-img' />

JQ

$('.upload-img').on('change',function(){
    var file = this.files[0];
        // 图片后缀  
        var suffix = file.name.split(".")[1];
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function(e) {
            // base64编码
            image_base64 = this.result.split(",")[1];
            console.log(image_base64);
        }
    });

If the next general TRANSFERRED base64 value, the need to spell pictures suffix, string concatenation can intercept the good suffix pieces together.
Before the first use of excessive post requests to upload pictures, post requests no theoretical limit to the size of the parameters, but the server is limited, resulting in failure to upload, then set about Tomcat's server.xml inside maxPostSize it. However, it is recommended to use Form submission form, make it more efficient.

Guess you like

Origin www.cnblogs.com/angenstern/p/11416313.html