Ich habe eine html:Parse: Posting hochgeladene Datei/Bild Backend
form.html:
<form method="post" enctype="multipart/form-data" action="/">
<input type="file" name="pic" id="imgupload">
</form>
<script>
document.getElementById("imgupload").onclick = function({myFunction()};
function myFunction() {
var fileUploadControl = $("#imgupload")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = "photo.jpg";
//how to pass this (parseFile) to server.js?
var parseFile = new Parse.File(name, file);
}
}
</script>
und mein Backend-Server Code Express:
vereinfacht server.js (nur Server-Routing):
app.get('/', (req, res) => {
//loads the form.html from above.
res.sendFile(__dirname + "/form.html");
})
app.post('/', (req, res)=>{
//once press submit button, will post parseFile to here
//from here, i will save the parseFile to database.
res.status(204).end();
})
Mein Ziel ist es, ein Bild hochzuladen, dann, wenn der Benutzer drücken Sie senden, die parseFile Variable wird gesendet an die app.post() in server.js, wo das Speichern stattfindet.
Ich habe versucht, multer, wo es nicht für Parse.File auf dem req.file nämlich funktioniert:
app.post('/', upload, (req,res)=>{
//req.file contains the file information
var file = new Parse.File(name, req.file);
//save to database via Parse
file.save(); //example code.
res.status(200).success("test code")
})
dieser Code gibt Typeerror in Parse wo Parse.File nicht in der Lage ist, ein Parse zu erstellen. Datei von req.file.
Jede Hilfe wird sehr geschätzt!
Vielen Dank im Voraus!