Help

Formula for files size in attachment filed

6332 16
cancel
Showing results for 
Search instead for 
Did you mean: 
Forms_PTA
4 - Data Explorer
4 - Data Explorer

I am having users attach photos and I would like a way to show the size of a file so that we can have an indication of the size of the file attached. Doesn’t anyone have a solution for this?

Thanks in advance for your help.

16 Replies 16
alex
5 - Automation Enthusiast
5 - Automation Enthusiast

I’m looking into this as well. You can enable “grouping” and then it’ll have an indicator for that specific group of total file size:
image

I’m trying to then take that total file size and roll it up into a connected table so that it shows up as just a line item. Does anyone know if this is possible? Just as you can pull in “Count”, can you pull in “Total File Size” for attached records using Rollup?

I need the “Total Attachment Size” column to just give the total attachment size for the images column.
image

Totally happy to calculate this in the original table for the line item if that’s what has to happen:
image

Can’t seem to figure it out though. Wish I could just take that “18MB” total field and have it passed through as a field in the other base.

@openside you’re a master, any ideas?

Thanks everyone!

Any luck on this? I’m trying to do the same so I can flag any images that are too large.

@Brent_del_Rosario unfortunately not :frowning:

What we ended up doing was using Integromat to shrink the sizes of the images uploaded to like 1/4th the size just in-case at the time of generating the email that we are appending the attachments in Airtable to.

Not ideal, but it has solved the issue for now. Still wish this was a data-point that we could roll-up and have triggered views and such based on it.

Check out this extension:

This is updated version of the post (I missed some pictures in my earlier post):

Has anybody found a solution? Can’t believe there is nobody. Searched google and it doesn’t look like anybody has ever searched or asked same question. Even Integromat community doesn’t have an answer.
The Miniextenion can do that but I can’t justify spending 40 USD for 1 extension if paying 10 dollar for Airtable.

I’ll contact Integromat support, see what they say. It’s easy to get one attachment size with Integromat. You just need the Airtable Watch module and the Airtable Updater module and that will write the attachment file size into a field of your choice.

The problem is, I couldn’t find how to get total size of all attachments in the particular field. Array functions were of no help, it can get files but I wasn’t able to get the sizes to add up. Even tried adding variables etc to no avail.

size
size1
size2
size3
size4
size5

Here's a related thread for a suggested feature (product idea) about attachment file sizes:
https://community.airtable.com/t5/product-ideas/attachment-file-size-type-limits/idi-p/55500

Alvaro_Hernande
6 - Interface Innovator
6 - Interface Innovator

I write this script into an automation. When an attachment field is updated, it gets the sum of all the files in the attachment field and put it into a number type field.

const table = base.getTable('Your Table Name');
const fieldWithAttachments = 'Attachments Field Name';
const fieldToStoreSizes = 'Sizes Field Name';

// Retrieve the specific record based on the provided recordId
const recordId = input.config().recordId;
const record = await table.selectRecordsAsync({ recordIds: [recordId] });
const selectedRecord = record.records[0];

const attachments = selectedRecord.getCellValue(fieldWithAttachments);

if (attachments) {
  // Iterate over each attachment in the field
  const sizes = attachments.map((attachment) => attachment.size || 0);
  const sum = sizes.reduce((acc, curr) => acc + curr, 0);

  // Update the sizes field with the calculated sum
  await table.updateRecordAsync(selectedRecord, {
    [fieldToStoreSizes]: sum,
  });
}

Remember to write your correct base name and fields in the three first lines

It works form me. Hope this solve the question.

😉

I tried this and I am getting this error? Any advice? 

Raquel4725_0-1693955800442.png

 

Alvaro_Hernande
6 - Interface Innovator
6 - Interface Innovator

Have you define in your automation input variables??

 

Alvaro_Hernande_0-1693979973626.png

That type of error seems to me that the script is not getting any value because input.config() not defined. But maybe if you give us more info we can understand better the issue.

 

😉

This worked great for me, thank you so much! 

Is it possible to put the result in a text field with a unit? What file size unit does your script put into the number field? 

@easecomm yes it is possible I did that in two parts (but you can use just one formula field to do that:

- First I have a column called sizeMB that converts the number to MB: Using this formula [

IF(Tamano,Tamano/1000000,0)] I use the if to avoid ERROR! when the attachment field is empty
Alvaro_Hernande_0-1706597699863.png

 

-Second, I append MB to the number: [
SUBSTITUTE((ROUND(TamanoMB,2) & " MB"),".",",") Here I add MB at the ende of the string and because I am at Europe, I change the "." with a "," for the decimals.]
 
Alvaro_Hernande_1-1706597722662.png

Is it possible, also, to do that inside the script, but airtable formulas work quite fast that i prefer this method.

Hope you find this helpful.

😉

 

Dear Alvaro, thanks for sharing your automation script. I wonder if you can assist me with troubleshooting the error I am seeing.

Thanks,

MikeScreenshot 2024-02-26 at 11.56.03 AM.png

 

Dear @Mike_Gendel :

The error message is indicating that recordId is undefined when it's being used in the selectRecordsAsync function. This could be because input.config().recordId is not returning a value.

To fix this, you need to ensure that recordId is defined before it's used. You could add a check to see if recordId is defined and throw an error if it's not. 

In this case, whe we are running a script inside an Automation, we need to set Input Variables here:

Alvaro_Hernande_0-1708942124101.png

That's why your script is giving you an error. And if you had already declare recordId variable. Please be sure that the names are exactly the same.
Hope this helps you!

Thanks. I replicated your settings but I still have an error. What am I missing? (By the way, as you can see, I am not an expert in scripting!)

Screenshot 2024-02-26 at 12.33.22 PM.png

 

hi everyone

Mike I have the solution for you, the place where you input the variable is case sensitive, you should write recordId and not recordid (the last I should be caps). I had the same problem and I solve it just like that.

Alvaro, sos un genio crack, really its amazing, you just save me 50 USD of miniextensions. works as a charm, if you ever read this message write me I would like you to work with me hehe

TristanARG_0-1710684350339.png