Get part of url

Hi, I have (Glide pages / glide table) a table with first column the URL of an uploaded file.
In the layout-options of the file-picker, I checked “Keep file name when uploading”.
So far so good.

But in another screen, I want to display (in a collection) all the uploaded files, but then I do not have a similar option. I can only show the whole URL.
I think I need a second column in my table (get part of url) to retrieve only the filename, but I do not know how.

Any help is appreciated !

You can use the Javascript column to extract the file name using this code:

  var segments = p1.split('/');

  // Get the last segment
  var lastSegment = segments[segments.length - 1];

  // Split the last segment by question mark or hash, if present
  var fileName = lastSegment.split(/[?#]/)[0];

  // Return the file name
  return fileName;

Where “p1” is the column with the full URL.

2 Likes

What does your URL look like and what part do you want to isolate?

I believe it gives you escape characters in some cases.

var segments = p1.split('/');

// Get the last segment
var lastSegment = segments[segments.length - 1];

// Split the last segment by question mark or hash, if present
var fileName = lastSegment.split(/[?#]/)[0];

// Decode URL-encoded characters
var decodedFileName = decodeURIComponent(fileName);

// Return the decoded file name
return decodedFileName;

Added a step to decode those.

2 Likes

thanks for helping; it works :slight_smile:

Just those extra questions (for new columns):

  1. is there a way to retrieve the extension of the file (like doc, or docx, or pdf,…)
  2. is there a way to retrieve the file-date ?

Try this :

var segments = p1.split('/');

// Get the last segment
var lastSegment = segments[segments.length - 1];

// Split the last segment by question mark or hash, if present
var fileName = lastSegment.split(/[?#]/)[0];

// Split the file name by dot (.) and retrieve the last element as the extension
var fileExtension = fileName.split('.').pop();

// Return the file extension
return fileExtension;

You mean the file created date? I guess it’s not possible. I checked a bit and we can get the modified date with js but couldn’t get the created date. If you want the added date you can use a date column and update that column when uploading the file!

Thank you

Hi Dilon_Perera,

  • thanks for the extension-script; works fine !

  • modified-date would be good; if you have some time to show the script…

Wim

I think this is the easiest way, unless you truly want to know the creation date from the metadata of the file, then that’s another issue.