Simple Plugin - Node Help - Get Image Size

Hi !
I’m trying to get image size from a fileURL, in a plugin
This simple code returns that cannot be interpreted as JavaScript.
Any help?

async function processImage(properties, context) {

const axios = require(“axios”);
const sizeOf = require(“image-size”);

try {
    const { fileURL } = properties;
    const response = await axios.get(fileURL, { responseType: "arraybuffer" });
    const dimensions = sizeOf(Buffer.from(response.data));

    return {
        width: dimensions.width,
        height: dimensions.height,
        error: "",
    };
} catch (error) {
    return {
        width: 0,
        height: 0,
        error: `Erro ao obter dimensões da imagem: ${error.message}`,
    };
}

}

bubble wants the code to start with async function(properties, context) { even though it’s not correct syntax :man_shrugging:

what should solve that?
It is assync, isn’t it?

it would solve this :point_up: , assuming that the rest of your code is valid js

I cannot understand…

the exact line. it’s because of bubble’s internal logic

I could not understand @dorilama … how to solve?
Simple function to read a file proprieties…
Bubble accepted this structure in another code…
What do you mean?

I’m at the end of my day and can’t explain it easier than this: bubble requires that the beginning of your code must be exactly the string I posted before, not any other thing, don’t add a name to the function. There is at least another topic about this exact problem in the forum. :wave:

1 Like

Thank You !!!
I’d never get that !!! :))

Cannot make it happen…
very simple function, lightweight lib (image-size)…
Any help?

async function(properties, context) {
const axios = require(‘axios’);
const sizeOf = require(‘image-size’);
try {
const { fileURL } = properties;
const response = await axios.get(fileURL, { responseType: ‘arraybuffer’ });
const dimensions = sizeOf(response.data);
return {
width: dimensions.width,
height: dimensions.height
};
} catch (error) {
return { error: Erro ao obter informações sobre a imagem: ${error.message} };
}
}

double check the quotes of your string, only ' " and ` are correct.
fyi you can paste multiline code in the forum by wrapping it in ```

Checked a thousand times… (20 lines of code…)
Some libs like “crypto” works like a charm…
While “Image-Size”, “fast-image-size”, “sharp”, " GraphicsMagick", and many other, doesn’t…

async function(properties, context) {
const axios = require(“axios”);
const sizeOf = require(“image-size”);
try {
const { fileURL } = properties;
const response = await axios.get(fileURL, { responseType: “arraybuffer” });
const dimensions = sizeOf(Buffer.from(response.data));
return {
width: dimensions.width,
height: dimensions.height,
error: “”,
};
} catch (error) {
return {
width: 0,
height: 0,
error: Erro ao obter dimensões da imagem: ${error.message},
};
}
}

Here is the code :slight_smile:

async function(properties, context) {
const axios = require("axios");
const sizeOf = require("fast-image-size");
  try {
    const { fileURL } = properties;

    // Fetch image data
    const response = await axios.get(fileURL, { responseType: "arraybuffer" });

    // Get image dimensions using fast-image-size
    const dimensions = sizeOf(response.data);

    return {
      width: dimensions.width,
      height: dimensions.height,
      error: "",
    };
  } catch (error) {
    return {
      width: 0,
      height: 0,
      error: `Error while obtaining image dimensions: ${error.message}`,
    };
  }
}

This code does not trigger the editor error in a server-side action.
What error do you get?
Are you using this code in a client-side action? Client side actions must be sync and must start with function(properties, context) {

Server Side
My intention is to use get data from “uploaded files”, in the BackEnd.
No error… it halts execution, nothing in the WF is executed after this simple plugin call;
I’ve tried many libs, same thing…
What is interesting, If I change this “same call” to return a hash, let’s say (sha256), with “cryto lib”, it works…
If I use a lib to get “Image Dimensions”, Bubble halts WF… (no matter the lib I use).
So, It is buffering, but cannot execute the lib function.

this is completely different from what you posted (the editor complaining about syntax error)

If you are using a library that was last published 7 years ago to run in a different environment I’m afraid there is nothing to do here.

for image-size there is documentation with enough examples, you should try them. If you want to try something different then you should try the code locally first, to have a better debigging experience, and then test it on bubble.

Good point @dorilama ! obsolete libs…
Which lib do you recomend for such a simple request?

check this out

I’ve tried “image-size” (my first attempt);
Then, I’ve tried : sharp, gm (GraphicsMagick), jimp