I know how to use bubble text to md5 hash, but In my case, I need the md5 of a file.
How can I get that using Bubble?
Thanks
Is that possible? Get md5 of a video file using bubble?
Create a plugin, add a server side action
Add a field called file
Add a New key called files_md5
const fetch = require('cross-fetch');
const crypto = require('crypto');
let result = context.async(async callback => {
let res = await fetch('https:' + properties.file);
let fileBytes = await res.arrayBuffer();
const hash = crypto.createHash('md5');
hash.update(Buffer.from(fileBytes));
const md5Hash = hash.digest('hex');
callback(null, md5Hash);
});
return {
files_md5: result
}
You probably know it already: the last version published of cross-fetch
is from 1 year ago and it depends on node-fetch
v2.
node-fetch
is already at v3.3 so you might want to use an updated library instead.
edit: I missed this info from the node-fetch documentation:
If you cannot switch to ESM, please use v2 which remains compatible with CommonJS. Critical bug fixes will continue to be published for v2.
Of course node-fetch v3 is not compatible with bubble’s server actions and you should be fine with node-fetch v2 and cross-fetch as long as they keep publish critical bug fixes.
I meant to ask you but got caught up. How did you get node-fetch to work?
My mistake. I don’t use node-fetch at all on bubble, and that’s why I missed a piece of info about v2.
I just updated my answer to reflect that your example, as of today, is totally ok.
I hope one day we will be able to use ESM in bubble plugins.
I think that’s coming. At least that’s how I took the last update.
I think the last update is more about this, hence the need to switch to async.
Still better than it currently is
there is always this:
const [body, status] = context.async(async (cb) => {
try {
const { default: fetch } = await import("node-fetch");
const response = await fetch("https://github.com/");
const body = await response.text();
cb(null, [body, response.status]);
} catch (e) {
cb(e);
}
});
return { body, status };
with this package.json
:
{
"dependencies": {
"node-fetch": "3.3.0"
}
}
Thanks big dog!