html5+ photo upload and select File Upload

Source: Internet
Author: User
Tags nativeui

The HTML page content contains the following tags:

                   <inputID= "Btn_select"type= "button"value= "Select from album" />                   <inputID= "Btn_takephoto"type= "button"value= "Take pictures" />                   <imgID= "Imgviewer"src=""alt= "No picture"width= "+"Height= "+"/>                   <inputID= "Btn_save"type= "button"value= "Confirm Upload" />

JS Implementation section:

(function() {    varurl = "xxxxxxxxxx uploaded file Address"; varfile; varW =NULL; //H5 Plus event handling    functionPlusready () {//w=plus.nativeui.showwaiting ();        //H5 when ready to bind a photo event                //Photo Stand-alone event$ ("#btn_takephoto"). Bind ("click",function() {            //Take PicturesPlus.camera.getCamera (). Captureimage (function(P) {Plus.io.resolveLocalFileSystemURL (P),function(Entry) {Console.log (Entry.tolocalurl ()); $("#imgViewer"). attr ("src"), Entry.tolocalurl ()); }, function(e) {outLine ("Read photo file Error:" +e.message);            });        });                  }); //Select from album$ ("#btn_select"). Bind ("click",function() {Plus.gallery.pick (function(P) {Console.log (P); $("#imgViewer"). attr ("src"), p);        });                }); //Uploading Files$ ("#btn_save"). Bind ("click",function() {            varwt =plus.nativeUI.showWaiting (); //read to file according to pathPlus.io.resolveLocalFileSystemURL ($ ("#imgViewer"). attr ("src"),function(Entry) {Entry.file (function(file) {varFileReader =NewPlus.io.FileReader ();                        Filereader.readasdataurl (file); Filereader.onloadend=function(e) {varF = $ ("#imgViewer"). attr ("src")); varfilename = f.replace (f.substring (0, F.lastindexof ('/') + 1), "); varparam ={filename:filename datainput:e.target.result.tostring ()}; //Custom Ajax MethodsToolhelper.asyncajax (URL, param,function(data, para) {wt.close (); if(Data[0].responsecode! = undefined && Data[0].responsecode! = "") {$.dialog.alert (data[0].responsemessage); } Else{$.dialog.alert ("Upload succeeded");            }                });          }             });                                            });    }); }    if(window.plus) {plusready (); } Else{Document.addeventlistener ("Plusready", Plusready,false); }    returnBaseobj ={save:saveedit};}) ();
JavaScript

The above two sections use the camera-related events and methods in the Dcloud html+, as well as the way in which IO fetches the file stream based on the address, and the image uploaded to the server is Base64, so if the server needs to save the picture needs decoding.

html5+ photo upload and select File Upload

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.