Webx.5 Photo Upload function

Source: Internet
Author: User

Photo
Navigator.camera.getPicture (onsuccess, Onfail, {quality:50, destinationtype:0,sourcetype:1});//Take photos to get Base64 pictures
function onsuccess (imageData) {
Data.newdata ({//photo complete added to data stored in image
"Defaultvalues": [{
fzid:fzid,//Primary Table ID
Imgurl: "Data:image/jpeg;base64," + Base64 code for imagedata,//pictures
imgtpye:statename,//Table State Type
phototime:datetime//Photo Time
} ]
});
}

Save to local Database

Please see previous article WebX5 sqllite additions and deletions

Http://www.cnblogs.com/pengyawn/p/4725166.html

Uploading pictures to the server

function Imgupload (names) {//upload the server's JS code
IMGURL//64 Code Image
phototime///Photo Time
custid//User ID
address//Picture Save location
for (var a=0; a<names.length;a++) {
var image = Names[a].imgurl;
var subpath= "* * *";
var name=names[a]. Custid+ "_" +names[a].phototime+ ". jpg";
var params={
image:image,/Picture Base64 Code
subpath:subpath,//Server storage Location
picname:name//file name
};
$.ajax ({//Please note the Post method using Ajax
Type: ' POST ',
url:names[a].address+ "* * *",
Data:params,
Success:success,
DataType: ' JSON '
});
}
var success = function (Resultdata) {//post-upload processing
Alert ("Upload file succeeded! ");
};
}

Background Get parameters

Import sun.misc.base64decoder;//need to configure access rules for the JRE system library

public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
String image = Request.getparameter ("image"). Substring (23);//Get the Base64 code of the parameter picture

The picture is stored in the location of the project at the server and then stitched to get the picture's storage location
String subpath = This.getclass (). GetResource ("/"). GetPath (). substring (1, +) + request.getparameter ("subpath");// Get Picture storage location
String picname = Request.getparameter ("Picname"). ReplaceAll ("-", "" "). ReplaceAll (": "," "). ReplaceAll (" "," ");// Get Picture Store Name
Base64decoder decoder = new Base64decoder ();//Picture base64 decrypt and save local
try {
FileOutputStream write = new FileOutputStream (new File (subpath + picname));//query picture address, create a new picture, if the address does not exist, create a new
byte[] Decoderbytes = decoder.decodebuffer (image);
Write.write (decoderbytes);
Write.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}

Xiao: Chongqing King 2015-08-19 15:58

Webx.5 Photo Upload function

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.