Flutter CTO Report 2024
Get insights about Flutter directly from CTOs, CIOs, Tech Leads, and Engineering Managers!

How to Limit a Video Upload to a Specific Time Frame?

Łukasz Garstecki
Backend Developer at LeanCode

Rating: 5.00 / 5 Based on 6 reviews

Aug 8th, 2022 • 8 min.
Free product design tips
Join our Newsletter for Expert Flutter Tips & Product Design Insights from our seasoned team!
By submitting your email you agree to receive the content requested and to LeanCode's Privacy Policy.
or follow us

One of the projects we delivered at LeanCode was building an application for Healthcare Industry - Quittercheck. Here you can check out the Case Study of the Quittercheck. This app uses modern media such as video - recorded by the user - to help them quit smoking. Users must record themselves while performing a nicotine test before the camera during a specific day and then upload it to the app. It's simple for the user, although this case hasn't been that simple from the backend perspective of the app. Why? The video needed to be uploaded on a specific day in the user's time zone and limited to that day while the Quittercheck's system serves several time zones. So the problem to solve was how to limit a video upload to a specific time frame.

By reading this article, you will find our tailored solution to limiting a video upload to a specific time frame.

Quittercheck’s video upload feature specification

As mentioned earlier, during the test day, the user must record themself performing a nicotine test shipped to them before starting their quitting plan. The test day is chosen randomly and is unknown to the user beforehand to prevent users from cheating. Moreover, the user cannot select the video of them taking a test from their video gallery to ensure the video was recorded on the expected day.

This feature is quite complex and requires considering some key problems the solution must take into account:

1. Different time zones

The feature requires the user to upload a test video on a given day, starting at 12:00 am and ending at 12:00 am on the next day. This may seem simple to achieve from the user's perspective, but for the system, it is not.

At first, the system needs to know in what timezone the user is. Midnight in London is not the same point in time as midnight in Beijing or New York.

Another issue is daylight saving time. Many countries use different times in summer than in winter. This results in two days in a year that doesn’t last twenty-four hours. We should consider how we want to handle those two days.

Since user plans take up to seven months of weekly testing, we need to be prepared that users may travel, and as a result, they may change their timezone. The system needs to somehow allow users to change their time zone for such cases on the one hand, but on another, it should not allow the change to affect the current test day so that users do not receive any extra time or accidentally shorten their time to perform a test.

2. Large file size

The testing process is time-consuming. It takes from 10 up to 20 minutes. In the case of videos that take that long, we need to consider the final file size, which will vary from a few hundred megabytes up to a couple of gigabytes. The exact file size isn’t easily predictable because it depends on the camera resolution and number of FPS, which may vary between devices. 

That said, we need to be cautious about the empty space on the device before the user starts their test. In the case of older devices, users may not have enough free space to save a video. It is crucial to make sure that we will be able to save the video before starting a test since users need to perform the whole test as one recording (so that we are sure that nothing shady was done to the test kit).

3. The upload of a video

After the user performs the recording, they must upload their nicotine-test video to the server for verification. In the case of large files, this may take a couple of seconds up to a few minutes, depending on the user’s internet connection. 

At the time of the upload, we shouldn’t block users from using their device since we already did so for the time of taking a test. Even though the feature we need to implement is quite complex, we should make it as simple and foolproof as possible for the end-users. 

Another thing that we need to remember is that we should expect the internet connection to be unstable. Mobile devices use wi-fi or mobile internet connection, which may be lost, reconnected, or changed. In those cases, we should allow the upload to continue from where it was stopped.

4. Ensuring that the user did not corrupt the video

We must remember that we want to ensure that the user doesn’t cheat by tampering with a recorded video. At all times, we shouldn’t allow users to manipulate a recorded file, and we must prevent users from uploading a video that was not recorded by the app.

5. Video validation

After the test is performed and uploaded to the system, there needs to be an option for the administrators to verify that the test was performed correctly and no nicotine was detected during the test.

Actions to take before limiting a video upload to a specific time frame

  • Communicate the need for video recording. The first challenge is ensuring the user knows they must perform a test video. The app we design will be used once or twice a week during a test day, so we need to have in mind the fact that users will not visit the app daily. That said, we should ensure that we clearly communicate the need to perform the test to the user. To achieve this, we can send push notifications, emails, and text messages to the user at different times of the day to maximize successful communication.

  • Another important thing is to clearly communicate what we expect from the user concerning performing the test and send instructions on how to do that properly.

  • It’s also necessary to consider common disturbances from the device. When a user performs a test, they may be distracted by phone calls, text messages, and notifications from other applications. This is important to consider since recording the video takes a lot of time. During the recording, we need the application to stay in the foreground of the device. If a user changes the application and answers a call, the application cannot continue the test recording. It is a limitation we cannot change, so it is critical to communicate that fact to the user before they start the recording. We may also encourage users to turn on do not disturb mode on their devices.

  • Uploading video when the user is connected to the wi-fi. As mentioned before, the file size users need to upload is large, so we should encourage users to use a wi-fi connection. The mobile transfer is usually slower, which may irritate the users. Many users have limited internet transfer on their mobile devices, so we should ensure that they want to use their mobile connection to upload a video.

  • Enable uploading in the background. During the upload, we should allow users to freely use their phones. In order to do that, we need to prepare a solution to upload the video.

Limiting a video upload to a specific time frame - our solution

To complete the uploading of a nicotine-test video feature, we prepared a system that collects users' timezone, generates random test days, and sends push notifications on the day the test needs to be performed. Push notifications redirect the user directly to the mobile application, where the user can see the instructions of a test and start the recording. 

The video is stored in the application data, which is unavailable to the user, so they cannot corrupt the video. After the recording user may rewatch the video and submit it to the verification. Then, the video is submitted in the background to the Azure Blob Storage, and the user is redirected to the application's home screen. The progress of the upload is displayed on the home screen, and in case of any problems with the upload, gets notified about that and can take action to resume the upload.

When a video is uploaded, it is ready for review by an administrator that checks if the test is passed or failed. After verification, the user is notified by a push notification about the result of the video review.

Problems we faced while implementing a video upload feature

During the development of the system, we faced some unexpected issues. The first one was connectivity issues during file upload on Samsung devices using a wi-fi connection. These devices were causing socket exceptions during video upload. The solution to this problem was retrying the upload.

When interacting with the video file, we cannot load and process the whole video at once due to the device's RAM limitations. If your app needs to interact with large files, always remember to process them sequentially. 

Another issue we faced was partially uploaded files. This can happen if the user starts the upload but loses the connection before the upload is finished. To solve this issue, we notify users by push notifications that they didn’t submit their test yet, and we prepared an option of retest that can be allowed by an administrator if they decide that the user deserves a second chance to upload a video. 

Summing up

This article describes the tailored approach to the challenge we faced while developing the Quittercheck app. We devised a solution that satisfied business requirements and mitigated technical limitations. It required refining the test process and flexible administration tools to satisfy clients when they experienced unexpected problems. We hope it can help you solve similar issues. If you need a team to build a complex application, reach out to our custom enterprise software development company.

Free product design tips
Join our Newsletter for Expert Flutter Tips & Product Design Insights from our seasoned team!
By submitting your email you agree to receive the content requested and to LeanCode's Privacy Policy.
or follow us
Rate this article
5.00 / 5 Based on 6 reviews

Read more

Bluetooth Low Energy in Flutter – An Overview

As the number of smart devices grows, so does the need to control them. Bluetooth Low Energy seems to be the best choice for connecting devices due to its low power needs. By reading this article you will find out how to begin developing a BLE app in Flutter.
BLE in Flutter

How to Create a Streaming App Based on Subscriptions?

In just a few years, streaming media services have caused a real revolution worldwide. We guide you through building a functional streaming app based on subscriptions. We based this article on knowledge derived from mobile applications delivered by us.
CEO attracts users to his new media streaming mobile app

Creating Mobile Commerce App – 4 Questions to Answer

mCommerce is as crucial for business as shopping through online web stores. Shoppers got used to the convenience of browsing a wide range of items and making online payments via mobile phones. Check these 4 essential questions necessary to answer before building the mCommerce app.
Mobile Developer is building mobile commerce application