Good evening everybody. I’m getting crazy with that…
In a few words I’m trying to take a photo and than upload it somewhere on a server.
I’m using cordova-camera-plugin (to take the shot) and cordova-file-transfer to send it to the server.
This is what I did, following the guide from https://cordova.apache.org/docs/en/6.x/reference/cordova-plugin-file-transfer/ (first example).
I omit the code that put the path to the photo I took, inside the fileToUpload field value.
Let’s say the path (from Android Studio emulated device) is: file:///data/user/0/io.framework7.myapp/cache/1616162951525.jpg
<template>
...
<form id="locationForm">
<input type="text" name="fileToUpload" id="fileToUpload" />
<input type="button" value="UPLOAD" id="saveAllData" class="button button-fill" />
</form>
</template>
<script>
export default (props, { $, $on, $f7 }) => {
$on("pageInit", () => {
$("#saveAllData").on("click", function (e) {
e.preventDefault();
var fileURL = document.getElementById('fileToUpload);
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
var win = function (r) {
alert("Code = " + r.responseCode);
}
var fail = function (error) {
alert("An error has occurred: Code = " + error.code);
}
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var ft = new FileTransfer();
ft.upload(fileURL, encodeURI("http://<myserver>/upload.php"), win, fail, options);
}
});
});
return $render;
};
Inspecting the content of my $_FILES[] array into my upload.php script, I see that it’s always empty.
In add, I the error function returns ERROR CODE 1 (file not found)
First of all, what’s that? options.fileKey = “file”;
“file” is the name of the field that contains my url =(in my case should be fileToUpload?)
I also tried another script, inside the sami official guide, but it’s very hard to undestand for me.
Any hint? I know… I’m a noob with that things, so I’m sure I made a mess!
Thanks