I have this form element:
<form action="/upload" method="POST">
<input type="file" id="img" name="image" accept="image/*" class="btn"/>
<button type="submit" class="btn">Upload</button>
</form>
When I submit the form, the post
request is getting the file name of the image through body-parser.
app.post("/upload", (req, res) => {
console.log(req.body.image);
const filename = req.body.image;
async function uploadFile() {
await storage.bucket(bucketName).upload(filename)
}
uploadFile().catch(console.error);
res.redirect("/upload");
});
The console.log
returns just the file name image.jpg
without the path. When the uploadFile()
method is called it returns an error saying that the file path does not exist, because it is saying the file path is: C:\\Users\Owner\Desktop\Serverfolder\image.jpg
which is completely wrong.
So how do I prepend the right file path that google cloud will accept? I know that the browser will protect the actual file path for file uploads, but it is not filling in the temporary or fakepath so that the image can be uploaded.
Please help, because the google cloud documentation is annoyingly vague on the matter...