We use Monaca to create hybrid apps for Android and iOS.
I would like to upload the file on the terminal to any FTP server.
I have installed the FileTransfer plug-in with the Cordova plug-in and am about to upload it with the code below.
var win=function(r){
alert("Success");
}
var fail = function(error) {
alert("failed";
console.log("upload error code" + error.code);
console.log("upload error source" + error.source);
console.log("upload error target" + error.target);
}
function hoge() {
var options = new FileUploadOptions;
options.fileKey="file";
options.fileName="myphoto.jpg";
options.mimeType="image/jpeg";
var params = {};
param.value1 = "ftpid"; // FTP server ID
param.value2 = "ftppassword"; // FTP server Pass
options.params=params;
varft = new FileTransfer();
var path="/sdcard/"+'monaca.jpg';
ft.upload(path,encodeURI("ftp.server.url.com"),win,fail,options);
}
The file is placed directly under /sdcard/ of the terminal.
This ft.upload seems to have failed, but in the log output with the above fail,
upload error code null
upload error source null
upload error target null
I don't know what it says.
Debugging environment is
Actual: NEXUS5
Android version: 5.1.1
Cordova version: 4.1.0
FileTransfer version: 0.4.8
Could someone please teach me
javascript monaca cordova
I solved myself.
ft.upload(path,encodeURI("ftp.server.url.com"),win,fail,options);
It seems that the designated ftp server part of was bad.
The FileTransfer upload function failed to upload the file directly to FTP.
It was resolved by placing a php for storing files on the server and specifying the php file by URL.
As a result, I chose the following code.
ft.upload(path,encodeURI("http://server.url.com/receive.php"),win,fail,options);
© 2024 OneMinuteCode. All rights reserved.