我有一个区域,我想要两个按钮加载相机并上传图片或加载图库然后上传图片。这是一个手机应用程序。
这有效: 的 HTML:
<a href="#" onclick="takep()"><img src="icons/camera-icon.png" /></a>
JS:
function takep(SessionKey, PetID) {
// Retrieve image file location from specified source
navigator.camera.getPicture(
uploadPhoto,
function(message) { alert('get picture failed'); },
{
quality : 50,
destinationType : navigator.camera.DestinationType.FILE_URI,
sourceType : navigator.camera.PictureSourceType.PHOTOLIBRARY
}
);
}
function uploadPhoto(imageURI) {
$.mobile.loading( 'show', { theme: "b", text: "Loading", textonly: false})
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = {};
var Username = localStorage.getItem("Username");
var SessionKey = localStorage.getItem("SessionID");
var PetID = localStorage.getItem("addPetID");
var callback = "moo0";
params.Username = Username;
params.SessionKey = SessionKey;
params.AnimalKey = PetID;
params.Filename = "moo";
params.callback = callback;
console.log(Username);
console.log(SessionKey);
console.log(PetID);
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://redacted/UploadFileCollection"), win, fail, options);
}
但是,这两个按钮都不会加载任何内容:
HTML:
<a href="#" onclick="capturePhotoWithData()" class="ui-btn ui-btn-inline">From Camera</a>
<a href="#" onclick="capturePhotoWithFile()" class="ui-btn ui-btn-inline ui-btn-b">From File</a>
JS:
function capturePhotoWithData() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(uploadPhoto, onFail, { quality: 50 });
}
function capturePhotoWithFile() {
navigator.camera.getPicture(uploadPhoto, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY });
}
答案 0 :(得分:0)
以下是有关phonegap媒体示例的链接:
来自一位手机员工:
https://github.com/ismael-jimoh/Media-FilePath
你可能不会在你的包中加入cordova.js ......这就是为什么它不起作用。