I'm working on a project where I need to upload many PDF files to a PocketBase collection.
I have all the files on my computer and I'd like to upload them using nodejs and the PocketBase JavaScript SDK. PocketBase expects me to send the file as a [file object], which is not possible in nodejs.
Ideally the code would look something like that:
const fileObject = loadFile(pathToFile);
const entry = {
nameField: "some-field",
fileField: fileObject
}
await pb.collection("my-collection").create(entry)
I didn't find any bits of code that could help creating a loadFile
function.
You are supposed to send your form as
multipart/form-data
when uploading files to pocketbase.Try:
Also, make sure you don't use
JSON.stringify
on your form when usingmultipart/form data
.Pro tip: if you leave out 'Content-type', it should default to
multipart/form-data
.