0

这就是我下面的内容,我提交表单的唯一方法是浏览图片。
有人可以告诉我如何用按钮提交这个,最好不用jQuery。
我只想提交一个带有文本的表单,没有图像。谢谢!

function browse()
{
    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)
{
    var options = new FileUploadOptions();
    options.fileKey="file";
    options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType="image/jpeg";

    var params = {};
    params.value1 = "test";
    params.value2 = document.getElementById('file_name').value + "";
}
4

2 回答 2

0

我认为您要问的是如何将图像从相机提交到服务器,而无需文件输入表单元素,用户必须在其中浏览文件等。

最简单的答案就是不要将图像存储为文件,而是将其保存为 base64 字符串。为此,请将您的目的地类型更改为

destinationType: Camera.DestinationType.DATA_URL

您的成功函数的参数现在将是一个 base64 字符串,您可以像任何其他字符串一样将其发送到您的服务器。然后,您需要在服务器端对其进行 base64_decode,然后将其写入磁盘。

于 2013-02-19T05:49:00.240 回答
0

尝试一个普通的 HTML 表单:

<form action="/post" method="post">
  Input: <input type="text" value="input something"/>
  Submit: <input type="submit" value="Submit"/>
</form>
于 2013-01-22T05:55:34.617 回答