// JavaScript Document
const efC = false; // forceCreation ein/aus
// *****************************************************************************
const strUpload = "0_userdata.0.UPLOADinVIS." ;
const subPfad = "/PicFromBrowserUpload";
const strPfad = "/opt/iobroker/iobroker-data/files/vis.0" + subPfad ;
createState (strUpload + "FileNameUpload" , "0", efC, { read: true, write: true, name: "FileNameUpload" , type: "string", def: 0 });
createState (strUpload + "uploadBase64" , "0", efC, { read: true, write: true, name: "uploadBase64" , type: "string", def: 0 });
createState (strUpload + "VerzeichnisUploads" , "0", efC, { read: true, write: true, name: "VerzeichnisUploads" , type: "string", def: 0 });
createState (strUpload + "myArrBuff" , "0", efC, { read: true, write: true, name: "myArrBuff" , type: "string", def: 0 });
createState (strUpload + "FileNameUploadOld" , "0", efC, { read: true, write: true, name: "FileNameUploadOld" , type: "string", def: 0 });
//######### Ab hier Funktion ########
FileUpload(); //Einmalig zur Initialisierung der Variablen
schedule("*/1 * * * * *" , FileUpload); // Jede Sekunde
function FileUpload()
{
var nameOfPic = getState (strUpload + "FileNameUpload").val ;
var nameOfPicOld = getState (strUpload + "FileNameUploadOld").val ;
if ( nameOfPic != nameOfPicOld ) // Bei änderung
{
var x = getState (strUpload + "myArrBuff").val ;
const fs = require('fs');
let myArrFiles=[]
let counter=0
log("schreibe file mit " + nameOfPic)
writeFile('vis.0',subPfad + "/"+nameOfPic,Buffer.from(x), function ()
{
fs.readdir(strPfad, (err, files) =>
{
if (err)
console.log(err);
else
{
console.log("\nCurrent directory filenames:");
files.forEach(file =>
{
console.log(file);
counter++;
myArrFiles.push({"Anzahl":counter,"Filename":file})
})
}
log(JSON.stringify(files))
setState(strUpload + "VerzeichnisUploads",JSON.stringify(myArrFiles))
})
})
}
setState(strUpload + "FileNameUploadOld",nameOfPic);
}