Photo Social App with FlutterFlow and Supabase · Course book
Chapter 10: Uploading Posts
The moment the photo app stops being a mock-up is when a user can pick a photo, write a caption, tap Share and see their post saved. This chapter connects the add-post pages built earlier to Supabase Storage and the posts table. It explains FlutterFlow's upload action and how the uploaded file's address is held in page state, how the chosen image is shown back to the user, how an Insert Row action creates the post with the author, address and caption, how actions are chained in the right order with conditions and navigation, and how to test the flow properly. It also works out by hand how image size affects the time a user waits after tapping Share.
The upload action
FlutterFlow's Upload Media to Supabase action does three things in one step: it opens the phone's image picker or camera, lets the user choose a photo, and uploads the file to a named bucket. Its settings choose the source, gallery, camera or both, the bucket, and limits on the image's maximum width, height and quality, which compress the photo on the phone before it is sent. After a successful upload, the action provides the uploaded file's address, which the page needs for the preview and for the database row. Without that address, the post would have no way to find its image later.
That address must be kept somewhere while the user moves from the add-post page to the details page. FlutterFlow offers page state for values that belong to one page, page parameters for values passed into a page when navigating, and app state for values the whole app shares. The cleanest approach here is to upload on the add-post page and pass the resulting address to the details page as a parameter, so that each page receives exactly what it needs.
Uploading as soon as the photo is chosen, rather than when Share is tapped, makes the final step feel instant, because the file is already in storage by the time the caption is written. The cost is that photos the user picks and then abandons are left in the bucket; a periodic clean-up of files not referenced by any post can remove them later.
The three kinds of state are worth understanding clearly, because the rest of the series uses all of them. Page state lives only while its page is open: a selected tab, a toggle, a value typed but not yet saved. It disappears when the user leaves the page. Page parameters are inputs a page receives when it is opened, such as the address of the uploaded photo or, later, the id of the post to show; they make pages reusable, because the same details page can display any post it is given. App state is shared by every page and can optionally persist on the device between launches, which suits values such as the signed-in user's profile or a list of liked post ids. Choosing the narrowest kind that works keeps the app easy to reason about: a value that only one page needs should not be global.
The upload can also fail or be cancelled. If the user closes the picker without choosing anything, the action produces no address, and the page should simply stay as it was. If the upload itself fails, because the network dropped or the file was too large for the bucket's limit, the page should say so and let the user try again. Checking for an address before enabling the Next button handles both cases with one condition.
Showing the uploaded image
Once the upload completes, the preview image widget on the add-post page is set to show the uploaded file's address instead of the placeholder. That gives the user immediate confirmation that the right photo was chosen and uploaded. While the upload is running, a progress indicator over the preview, or a disabled Next button, tells the user to wait.
On the details page, the same address fills a small thumbnail beside the caption field. Showing the image again here is a small touch with a purpose: users can check what they are about to share while writing about it. If the user goes back and chooses another photo, the parameter changes and the thumbnail updates, while the caption already typed should be kept.
Inserting the post row
When the user taps Share, an Insert Row action adds a row to the posts table. FlutterFlow lists the table's columns, which it knows from the schema, and each is set to a value.
| Column | Value set by the action | Notes |
|---|---|---|
| user_id | The authenticated user's id | The author; checked by the insert policy |
| image_url | The page parameter holding the uploaded address | Required |
| caption | The caption field's current text | Trimmed of extra spaces |
| id, created_at, like_count | Not set | Filled by the database defaults |
Columns with defaults are left alone, so the database generates the id, records the current time and starts the like count at zero. The row level security policy for inserting into the posts table should check that user_id equals auth.uid(), so that nobody can create posts in someone else's name, even with a modified app.
The caption deserves a little processing before it is saved. Removing spaces and blank lines from the start and end keeps posts tidy, and a maximum length, enforced both by the text field and by a check constraint in the database, prevents unbounded text. Hashtags and mentions can stay as plain text for now; later features could extract them into their own tables to make them searchable or to notify mentioned users.
Chaining actions in the right order
A button in FlutterFlow can run a sequence of actions, each waiting for the previous one to finish. For the Share button, the sequence is: validate that an image exists and the caption is within its limit; show the button's loading state; insert the row; and, if the insert succeeded, navigate back to the home feed, or show an error and stay on the page if it failed.
Navigation after posting needs care. Going back with a plain back action returns to the add-post page, which is not what the user wants. Navigating to the home page, or popping back past both creation pages, lands the user on the feed. Some designs also reset the bottom navigation bar to the home tab. After navigating, the feed's query should refresh so the new post appears at the top; FlutterFlow can refresh a query when its page loads, or the feed can be rebuilt after the insert. A brief confirmation, such as a snack bar reading "Post shared", reassures the user that everything worked, especially if the new post is not immediately visible because of caching or ordering.
How long does sharing take?
The wait a user feels depends on how much data must travel. Upload time is the file size in bits divided by the upload speed.
Testing the flow
Test the whole flow on a real phone: pick a photo from the gallery, take one with the camera, write a caption, share, and check that the post appears in the feed and in the Supabase table editor, with the image visible in the bucket. Then test the awkward cases: cancelling the picker, sharing with an empty caption if allowed, a very long caption, a poor network, and going back and choosing a different photo. Finally, make sure the bottom navigation bar shows the right tab after posting. A short recap at the end of each part, listing what was added and what remains, is a good habit that makes the next part easier to start and keeps the project on track.
Practice tasks
- Compute the upload time for a 2 MB photo and a 250 KB photo on a 4 megabit per second connection.
- Which columns does the Insert Row action set, and which are filled by defaults?
- Explain why the uploaded address is passed to the details page as a parameter.
- What should happen when the insert fails, and why must the user's caption not be lost?
- Write the insert policy for the posts table in words.
- Describe how to make the new post appear at the top of the feed after sharing.
This course book is available to read online only at tech-academy.chrysolites.org.