Phonegap で入力ファイルを使用することはできません。サポートされていません。次のようなものを作成する必要があります。
function onDeviceReady() {
// 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)+'.png';
options.mimeType="text/plain";
var params = new Object();
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://some.server.com/upload.php"), win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
getPicture メソッドでは、ファイル ソースを選択します。詳細情報を参照してください: http://docs.phonegap.com/en/2.1.0/cordova_file_file.md.html#FileTransfer
編集:
テキスト形式で画像を送信するには、「text/plain」形式で mimeType を要求するだけでなく、fileName 拡張子を指定する必要がありました。パラメータについては、必要ないのになぜ使用するのでしょうか?