Need help with Custom Javascript

Hi !

I need to find the extension of a file upload (using weweb file upload pre-made component).

I can’t find any weweb feature that allow me to find the extension, therefor I am trying to get it using a custom javascript.

I have a problem when running the code, it seems like the substring function is not found. Any idea why ?
Any suggestion on how to do this ?

Welcoming any inputs. Many thanks.

Here’s my code, with error log :


Basically, I’m tryintg to return “logo_someothervariabletext.extension”

it looks like you are missing something in the first assignment because you are looking for a name property in an array. are you looking to input a variable?

I’m indeed looking for that ‘name’ variable. That’s how weweb handles it’s objects from what I gather.
The object is File1, I want File1.name.
That part is fine and validated. When I remove the substring() part of the code, there are no errors.

look at the rest of your code: you have something like variables['long-uid'], variables is an object available in the scope of your code and you are accessing one of its properties that is a weweb variable (you are probably inputting this code with the helper interface by selecting the variable).
the beginning of your code is different, it’s only ['long-string'] that on its own is just an array that of course does not have a name property. you miss the initial object you want to access.

try inserting the variable again with the helper interface so that you can have the complete code for that.

1 Like

You’re totally right. The keyword ‘variables’ was actually missing from the code to access the object. Probably some copy/past error on my end. Didn’t notice it. Many Thanks.

I fixed the code this way :

Result :
Screenshot 2024-04-24 at 11.04.55 AM

1 Like