繁体   English   中英

通过phonegap加载相机或图库

[英]Loading either Camera or Gallery through phonegap

我有一个区域,我想要两个按钮来加载相机并上传图片或加载图库,然后上传图片。 这是一个phonegap应用程序。

这有效: 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 });
}

这是有关phonegap上的媒体示例的链接:

它是来自phonegap员工的:

https://github.com/ismael-jimoh/Media-FilePath

您的软件包中可能没有包含cordova.js ...这就是为什么它不起作用的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM