我很难知道如何让Filetransfer APi作为提交表单的一部分工作。目前您选择一张图片并将其自动发送到服务器但是对于应用程序我需要使用其他数据发送。我有其他部分正常工作,我需要的只是基于文本/选项,但我很难与图像。
atm我只是看着zac葡萄园代码示例
<!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>
如果有人有任何想法,那将会非常有用。我尝试了很多不同的东西。我已经让它在桌面平台上工作,但是当我使用我的Android手机时,如果这与它有关。它不起作用。感谢
答案 0 :(得分:0)
您可以将要发送的键/值对添加为“params”对象的成员。如果您想发送uid = 1234和server = na,那么您可以这样做:
var params = new Object();
params.uid = "1234";
params.server = "na";
答案 1 :(得分:0)
您可以发送其他数据,例如objetId和图像:
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1)+".jpg";
var upload_url="http:YourDomain.com
/upload?token="+objectId+"&filenaam="+options.fileName;
ft.upload(imageURI, upload_url, win, fail, options);