标签:des style blog http color os 使用 java io
js代码 可以完全从 phonegap 官网扣下来
使用的是2.3版本的phonegap
<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:‘); //上传上传上传上传上传 try{ var options = new FileUploadOptions(); //用于设置参数,服务端的Request字串 options.fileKey = "fileAddPic"; alert(imageData); options.fileName = imageData.substr(imageData.lastIndexOf(‘/‘) + 1); alert(‘1:‘ + options.fileName); //如果是图片格式,就用image/jpeg,其他文件格式上官网查API options.mimeType = "image/jpeg"; //这里的uri根据自己的需求设定,是一个接收上传图片的地址 alert(‘2:‘ ); 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); } } // ??????õ?????????URI?????? function onPhotoURISuccess(imageURI) { // ????????????????URI // console.log(imageURI); // ???????? var largeImage = document.getElementById(‘largeImage‘); // ?????????????? largeImage.style.display = ‘block‘; // ??????????? // ??????CSS???????????? largeImage.src = imageURI; } // ??Capture Photo?????????¼????????? function capturePhoto() { // ????豸??????????????????Base64????????????????? navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI }); } // ??Capture Editable Photo?????????¼????????? function capturePhotoEdit() { // ????豸??????????????????Base64??????????????????? navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true, destinationType: Camera.DestinationType.FILE_URI }); } //??From Photo Library??/??From Photo Album?????????¼????????? 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>
后台代码 。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为app端FileUploadOptions传入参数,此点非常重要 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"); } }
标签:des style blog http color os 使用 java io
原文地址:http://www.cnblogs.com/sxmny/p/3944817.html