Pure native JS mobile image compression upload plug-in

Source: Internet
Author: User

Some time ago, colleagues again to consult a question, said mobile phone end motionless photo on several m HD large picture, upload server too slow, ask if I can compress the picture and upload JS plugin, of course, not on hand, do not panic, I go online search.

The result, hehe ... EH ~ and all is based on jquery, Zepto (this sentence seems to be too many times to vomit ...) ), and then I will not spit out the groove,

Then of course it was done by myself, first:

Pure native JS mobile image compression Upload plugin, do not rely on any library

Usage

The input tag is introduced into the HTML page, and the data-LUploader tag ID that is triggered by the custom attribute binding point is as follows:

<Divclass= "Luploader"ID= "Demo1">        <Divclass= "Luploader-container">            <inputData-luploader= ' Demo1 'Data-form-file= ' Basestr 'Data-upload-type= ' Front 'type= "File" />            <ulclass= "Luploader-list"></ul>        </Div>        <Div>            <Divclass= "icon Icon-camera font20"></Div>            <P>Click Upload</P>        </Div>    </Div>

By assigning a custom property such as an data-form-file assignment basestr to the upload base64 string parameter name and other custom attribute assignments to determine the other post parameter key values, as a result data-upload-type=‘front‘ , the post parameter will look like this:

{  formFile:data:image/jpeg;base64,/9j/4 ...,  Uploadtype:front}

To introduce a style file to the page:

<rel= "stylesheet"  href= "Css/luploader.css">

Also introduce the JS file to the page:

<src= "Js/luploader.js"></script> 

Initialize the plugin:

New Luploader (This puts the input object that needs to be bound as            a parameter, {",///POST request address            false,// if uploading multiple files at once defaults to False            maxsize:102400,// Ignore compression operation file volume limit default 100kb            accept: ' image/* ',// upload Image type             showsize:false// whether the original file size is displayed by default false        });

Project Address: Https://github.com/xfhxbb/LUploader

Alone Lele is not as many Lele, if the partners do not have good mobile phone-side upload picture plug-in than the first to take me this to deal with it!

Pure native JS mobile image compression upload plug-in

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.