【发布时间】:2012-05-27 23:55:24
【问题描述】:
我不知道如何让 Filetransfer APi 作为提交表单的一部分工作。目前,您选择一张图片并将其自动发送到服务器,但是对于应用程序,我需要与它一起发送其他数据。我需要其他部分正常工作,这只是基于文本/选项,但我被图像难住了。
atm 我只是在看 zac vineyards 代码示例
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4 /strict.dtd">
<html>
<head>
<title>File Transfer Example</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
function onDeviceReady() {
// Do cool things here...
}
function getImage() {
// 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) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://yourdomain.com/upload.php", win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
alert(r.response);
}
function fail(error) {
alert("An error has occurred: Code = " = error.code);
}
</script>
</head>
<body>
<button onclick="getImage();">Upload a Photo</button>
</body>
</html>
如果有人有任何想法,将不胜感激。我尝试了很多不同的东西。我已经让它在桌面平台上工作,但是当我使用我的手机时,如果这与它有任何关系的话。它不起作用。谢谢
【问题讨论】:
-
您已经通过选项对象发送了额外的数据。查看 options.params 对象。
标签: android image forms cordova file-transfer