Get the file size of multiple files uploaded with multi-file uploader (solved)

Hello everybody!

Using the multi-file uploader, I allow a user to upload multiple files at once.
I save the files (the links of the files) in a database data type, let’s call it User_File.
I use the following fields:
User_File fields:

  • file: type file
  • size: type integer

Using the KW List shifter I create a new User_File for each uploaded file.
I also want to store the file size in the “size” field.

Unfortunately, the Multi-File Uploader doesn’t return the file size (in contrast to the simple File Uploader that only uploads a single file).

How can I get the size of the files? I am thinking of some backend workflow. Maybe send some custom request to the file URL that returns just the file size but until now I didn’t manage to make it work. I couldn’t find a suiting action yet while tinkering with the backend workflows. Any ideas I can tackle this?

UPDATE:
So I managed to do this with the following API workflow: (note that the actual field name I am using is called N_file, instead of User_File). I used the javascript Toolbox plugin to do a HEAD request (server script 1) that contains the file size in bytes and I extracted that info (server script 2).




image

And I just schedule an API workflow, either for each item separately, or I’ll call an API workflow for a list of things
(for a single item)
image
(for a list of things)
image

2 Likes

Hello @BenjaminP welcome to the community.

Explore the advanced multi uploader plugin from Zeroqode @ZeroqodeSupport @levon . It may do the trick. :smiley:

2 Likes

Thank you so much for your answer! I did check it out and it seems that it would work as a solution. For now I managed to solve it with an API workflow. But I’ll consider implementing the multi-file uploader from Zeroqode in the future as well. It sure is faster!

2 Likes

Hi @BenjaminP
I am trying your solution but I get a 403 code error with my private files. When they are not private I get the size.
Any idea how to get access to the size of private files ?

I’ve been playing around to find a solution. To circumvent the 403 code error you need to remove the “http:” from the request. I noticed that this happens only on private files because there is a mediatory URL that is stored as an https: address which then leads you to the real address through some form of authentication. Since this mediatory URL redirects you to the real file you should be able to extract the file size from the mediatory URL if you manage to grab it. Thus, the HEAD request should be used on the mediatory URL and not on the initial URL. Maybe this helps you a bit in finding a solution. Right now I got my hands full so I don’t have the luxury to solve it. If you manage to crack it I would be interested in the solution you came up with.

Hi @BenjaminP

I already removed the http as in the private file rule there is already https.
I tried many things like adding a bearer token (i get error 401) or adding into the file url a token api (i get error 403)…

This topic was automatically closed after 70 days. New replies are no longer allowed.