Phonegap photo upload photo

Source: Internet
Author: User

JavaScript code can be fully deducted from the official phonegap website.

The phonegap Version 2.3 is used.
<SCRIPT type = "text/JavaScript" src = "cordova-2.3.0.js"> </SCRIPT> <SCRIPT type = "text/JavaScript"> var picturesource; var destinationtype; document. addeventlistener ("deviceready", ondeviceready, false); function ondeviceready () {picturesource = navigator. camera. picturesourcetype; destinationtype = navigator. camera. destinationtype;} function onphotodatasuccess (imagedata ){//????????? Base64 ???????????? // Console. Log (imagedata );//???????? VaR smallimage = Document. getelementbyid ('smallimage ');//?????????????? Smallimage. style. Display = 'block ';//??????????? //?????? CSS ???????????? Alert ('0: '); smallimage. src = imagedata; alert ('1: '); // upload, upload, and upload try {var Options = new fileuploadoptions (); // used to set parameters, the request string options on the server. filekey = "fileaddpic"; alert (imagedata); options. filename = imagedata. substr (imagedata. lastindexof ('/') + 1); alert ('1: '+ options. filename); // if the image format is used, use image/JPEG. For other file formats, check the API options on the official website. mimetype = "image/JPEG"; // The URI here is set according to your own needs. It is the address of alert ('2: ') for receiving and uploading images :'); VaR uri = encodeuri ("http: // 192.168.1.71: 803/up. aspx "); options. chunkedmode = false; alert (3); var Ft = new filetransfer (); alert (4); ft. upload (imagedata, Uri, function (MSG) {var response = MSG. response; alert ('OK' + response) ;}, function (MSG) {var response = MSG. response; alert ('no' + response) ;}, options); alert ('00');} catch (EE) {alert (EE. message );}}//?????? Parameters ????????? Uri ?????? Function onphotourisuccess (imageuri ){//???????????????? Uri // console. Log (imageuri );//???????? VaR largeimage = Document. getelementbyid ('largeimage ');//?????????????? Largeimage. style. Display = 'block ';//??????????? //?????? CSS ???????????? Largeimage. src = imageuri ;}//?? Capture photo ????????? Parameters ????????? Function capturephoto (){//???? ?????????????????? Base64 ????????????????? Navigator. Camera. getpicture (onphotodatasuccess, onfail, {quality: 50, destinationtype: Camera. destinationtype. file_uri });}//?? Capture editable photo ????????? Parameters ????????? Function capturephotoedit (){//???? ?????????????????? Base64 ??????????????????? Navigator. Camera. getpicture (onphotodatasuccess, onfail, {quality: 20, allowedit: True, destinationtype: Camera. destinationtype. file_uri });}//?? From photo library ?? /?? From photo album ????????? Parameters ????????? Function getphoto (source ){//??? ???????????????? Uri navigator. Camera. getpicture (onphotourisuccess, onfail, {quality: 50, destinationtype: destinationtype. file_uri, sourcetype: Source });}//??? ??????????????? Function onfail (mesage) {alert ('failed' because: '+ message) ;}</SCRIPT>

 

 

Background code. Net

Protected void page_load (Object sender, eventargs e) {file. writealltext (server. mappath (". ") +"/lg.txt "," 11 "+ datetime. now. tostring () + "\ n \ r"); httppostedfile file = request. files ["fileaddpic"]; // fileaddpic is the input parameter of fileuploadoptions on the app end. This is very important string filename = file. filename; string folder = "~ /Upload "; string uploadpath = httpcontext. Current. server. mappath (Folder +" \ "); If (file! = NULL) {file. saveas (uploadpath + filename); response. Write ("Err") ;}else {response. Write ("OK ");}}

Attachment

Phonegap photo upload photo

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.