userbase icon indicating copy to clipboard operation
userbase copied to clipboard

Allow buffer in order to upload files (userbase-js-node)

Open Fubinator opened this issue 4 years ago • 1 comments
trafficstars

I'm playing around with userbase-node-js right now. So far it's running really well, good job! One thing I noticed is that the uploadFile function expects an object of the File class, which is not available in node as far as I know.

What would be great would be if you could use node's File System API directly, for example with fs.readFileSync. The problem with this is that fs.readFileSync returns a buffer. This buffer must first be converted to a compatible format. Is there a way to do this in node at all? If so, the following way of uploading a file would still be very convenient:

const file = fs.readFileSync("/path/to/file.txt");

await userbase.uploadFile({
  databaseName: "...",
  itemId: "...",
  file
});

Fubinator avatar Jan 20 '21 12:01 Fubinator

Yep! Definitely possible and sensible. Good call. Added to the backlog

(userbase-js-node polyfills the File class so it's available to you as a global in node too btw)

j-berman avatar Jan 20 '21 20:01 j-berman