top of page
Preloader for File Upload

Preloader for File Upload

Display a preloader while a file is uploading

Intermediate.png

Beginner

3K

Published:

November 26, 2020

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

In this example we display a preloader animation while a site visitor uploads an image.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It

Page Elements

We added the following elements to our page:

  • Upload button: For site visitors to upload an image.

  • Image: For displaying the uploaded image. Initially displays a default image.

  • Container: Contains the preloader GIF. Initially set as Hidden in the Properties & Events panel. Shows only while the visitor’s image is uploading.

  • Image: The preloader GIF.

 

Code

Our code does the following:

  1. Store the current image as the default image.

  2. When the upload button changes, indicating that a site visitor clicked the upload button or clicked the X under the button to cancel the current upload, do the following:

  3. If the button’s value is greater than 0, indicating that a file is pending upload, show the preloader.

  4. Set the image source to null so the old image doesn’t show while setting the new uploaded image as the source.

  5. Start the upload process. Once the file is uploaded, set it as the displayed image.

  6. If the upload was unsuccessful, log an error.

  7. Hide the preloader either when the file finishes uploading or after logging an error.

  8. If there are no files pending upload when the button changes, indicating that the site visitor clicked the X under the button to remove the uploaded file, reset the image to the default image.

APIs We Used

Non-code example.

Non-code example.

Related Articles

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Image Fit Mode

Image Fit Mode

Experiment with different ways to fit your image in an image element

Intermediate.png

Beginner

Print on Demand

Print on Demand

Change the color, add text or upload images to personalize products.

Intermediate.png

Advanced

Hide and Show an Image

Hide and Show an Image

Show and hide an image according to the clicked button.

Intermediate.png

Beginner

Anchor 2
bottom of page