Managing files uploaded by users

Hello,
I am building an app that includes some forms, these form contain file upload options.
My concern is how I will be able to manage my storage, can I delete some files uploaded by the users of my app?

Thanks

Following.

I am switching to a Postgres data source and am trying to think about the architecture when a file is uploaded, and how it would all work given Postgres does not store files.

@jafarhajeer what is your datasource? That usually handles the storage.

Hi All, sorry for this small resurrection, I have exactly the same question.
I give users the ability to upload some files, and in my data source (postgress) I just get an url to the file that is stored by Softr.
How can I manage these files, for example delete them on an user’s request?

Here you can see an obfuscated example of a content link I see in the db:
https://app-files-v1.softr-files.com/applications/app-id/uploads/upload-id/file-name.png.

Upon browsing to the url it gets redirected to amazonaws but no browsing in the assets in possible.

I resolved this same issue recently with Softr Support (David and Aramayis were very helpful).

TLDR – You need to host your files through SSL on a webserver and return those file urls to Softr as a comma+space delimited “, “ string to be able to use those files as an Image, Image Gallery, File, or URL field type.

So… if you had a people table and a files table, you’d want to use a select query like this:

   SELECT a.id,
    a.name,
    string_agg(b.file_url, ', '::text) FILTER (WHERE b.id IS NOT NULL) AS file_attachments
   FROM people a
     LEFT JOIN files b ON a.id = b.related_id
  GROUP BY a.id, a.name;

Which would produce a file output like this:

Single file output:
https://example.com/file.pdf

Multiple file output:
https://example.com/file.pdf, https://example.com/file.png, https://example.com/file.jpg

IT’S ABSOLUTELY CRITICAL THAT THE DELIMITER IS COMMA+SPACE – COMMA ALONE WILL NOT WORK.

Which feels like a bug… right?

As a bonus… :rocket: :rocket: :rocket:

Supporting File Previews

If you want to preview your file attachments, format your output as an embed AND use the Softr EMBED field type to render the content.

SELECT a.id,
    a.name,
    string_agg(
        '<embed src="' || b.file_url || '" type="' || b.mime_type || '" />',
        E'\n'
    ) FILTER (WHERE b.id IS NOT NULL) AS file_attachments
FROM people a
    LEFT JOIN files b ON a.id = b.related_id
GROUP BY a.id, a.name;

Which would produce a file output like this:

Single file output:

<embed src="https://example.com/file.pdf" type="application/pdf" />

Multiple file output:

<embed src="https://example.com/file.pdf" type="application/pdf" />
<embed src="https://example.com/file.png" type="image/png" />
<embed src="https://example.com/file.jpg" type="image/jpeg" />

Mandatory

  • You MUST have a column that stores the mime_type for the file in your files table OR use some slick SQL to render that based on the file extension of the file. (I highly recommend the former.)