Is it possible for the upload form submission to wait until the file processing is finished?

Is it possible for the form submission to wait until the file processing is complete?

I am currently using web2py and its sqlform to upload a video file. As the file is being uploaded, it is also being converted to flv format. The progress of both uploading and encoding is displayed through two separate progress bars using the following code (http://www.web2pyslices.com/slice/show/1337/upload-progress-in-web2py). The encoding process begins on the backend as soon as the system detects that the video is being uploaded. Once both the encoding and conversion processes are complete, the user can play the converted video.

The issue that I am facing is that the form is accepted once the upload is complete even though the encoding process is still ongoing. I have tried using event.preventDefault(), but this prevents the progress bar from displaying properly. It seems that the default submit action cannot be stopped at the moment the upload completes. Is there any way to prevent the form from submitting until the conversion process is finished, and then proceed with the submission? Thank you!

Answer №1

To ensure form validation without database insertion, refer to this resource. Following validation, implement a continuous loop to monitor the completion of encoding. Once encoding is done, proceed with the database insertion and return.

def video_upload():
    upload_form = SQLFORM(db.encodeupload)
    if upload_form.validate():
        session._unlock(response)
        [while loop to verify file encoding completion]
        db.encodeupload.insert(**db.encodeupload._filter_fields(form.vars))
    [remaining code]

Within the while loop, consider checking for any errors during the encoding process and refrain from inserting (providing an error message) in such instances.

It's important to note that session._unlock(response) unlocks the session file before entering the loop. This step ensures that the locked session file doesn't impede the Ajax requests made by the page to update the encoding progress bar. Additionally, in the controller action triggered by the Ajax requests, remember to include session.forget(response) to prevent locking or writing to the session.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the purpose of employing useMemo in the Material-UI autocomplete documentation?

My focus is on this specific demo in the autocomplete documentation. In the google maps example, there is a throttled function that is returned from a useMemo with an empty array as the second parameter. However, it raises the question of what exactly is ...

Dealing with JSON variables in PHP and jQuery to obtain a string variable instead

Currently, I am retrieving a text from a php script via ajax using jquery. The code looks like this: $.ajax({ dataType: 'json', url: 'someURL.com', success:function(result){ json = ...

What is the best way to access event.target as an object in Angular 2?

Apologies for my limited English proficiency. . I am trying to write code that will call myFunction() when the user clicks anywhere except on an element with the class .do-not-click-here. Here is the code I have written: document.addEventListener(' ...

What is the method to extract div text using Python and Selenium?

Is there a way to extract the text "950" from a div that does not have an ID or Class using Python Selenium? <div class="player-hover-box" style="display: none;"> <div class="ps-price-hover"> <div> ...

Matching patterns and removing four lines that match the specified pattern

I currently have 2 separate files that I am working with. Within File 1, there is an Identifier (e.g. DF:1:1) as well as an additional field of "1:N". The following 3 lines are specific to the given Identifier. File 2 contains a column of various Identifie ...

Writing and altering content within the <code> element in Chrome is unreliable

Utilizing a WYSIWYG Editor with contenteditable functionality allows users to input "code snippets" using a <code> element. Here is an example: <div contenteditable="true"> <p> This is a paragraph with an <code>inline s ...

jQuery form validation not functioning as expected

I'm attempting jQuery form validation but encountering issues with the desired functionality. I would like the border of an input to turn red when it's empty upon focus out. Alternatively, I aim to incorporate the "has-danger" bootstrap class to ...

My JavaScript functions are not compliant with the HTML5 required tag

I am currently developing input fields using javascript/jQuery, but I am facing an issue with the required attribute not functioning as expected. The form keeps submitting without displaying any message about the unfilled input field. I also use Bootstrap ...

Tips for making a Python list without utilizing the range function in For Loops

If we take the string myString = "ORANGE" How can we implement a loop that displays each character with its position as shown below? 1O 2R 3A 4N 5G 6E I'm facing some confusion on how to achieve this without utilizing range. ...

Sending values to URL using the <a> tag in HTML

I currently have the selected language stored in a variable (var lan= urlParam('language')). I am trying to pass this language as a parameter (without PHP) in a URL within an "a" tag, like so: <a href="http://hotelscombined.sitewish.gr/HotelN ...

The value for $routeParams.param appears to be undefined

I have set up a route and am attempting to send parameters to a controller: app.js .config(function($stateProvider, $urlRouterProvider) { $stateProvider .state('spot', { url: "/spot/:param", templateUrl: "templates/spot.html", ...

Troubleshooting a Vue.js issue: How to fix a watch function that stops working after modifying

I have encountered a problem with my code. It seems to be working fine initially after the beforeMount lifecycle hook, but when I try to modify the newDate variable within my methods, it doesn't seem to track the changes. data() { return { ...

Using dryscrape for web scraping: encountering an issue when selecting a radio button with CSS

I am attempting to extract data from a dynamically updated table on a webpage using dryscrape. The web page in question is located at . My code functions correctly with tables that are generated when the page is loaded initially. However, I now need to upd ...

Is there a way to capture all ajax responses?

Is it possible to capture all responses from an ajax request, regardless of the library being used such as jQuery, prototype, or just the vanilla XMLHttpRequest object? I am looking for a way to append to any existing handler without removing it. Thank y ...

Capture all Fetch Api AJAX requests

Is there a way to intercept all AJAX requests using the Fetch API? In the past, we were able to do this with XMLHttpRequest by implementing code similar to the following: (function() { var origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.p ...

Python script that iterates through multiple pages to gather a list of elements

In my software, I have a database table containing information about users. However, due to the large number of users, this table is split into multiple pages. I am looking for a way to extract a complete list of all users across these pages using Selenium ...

node js retrieves information from the request body

Hey there! I'm diving into the world of Node.js and JavaScript, but I've hit a roadblock. I'm trying to fetch data from a URL using node-fetch, then parse it as JSON. However, I keep running into the issue of getting 'undefined' in ...

Limiting Ant Design Date range Picker to display just a single month

insert image description here According to the documentation, the date range picker is supposed to display two months on the calendar, but it's only showing one month. I carefully reviewed the documentation and made a change from storing a single va ...

Choose not to alter the display value during keyup and keydown events, while still triggering the change event

$(function(){ $(".cls_user_details select").keyup(function(){ $(".cls_user_details select").val("Profile"); }) }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="cls_user_setti ...

Tips for installing npm packages using a python script in the same directory as my script

The desired file structure should resemble this: test.py node_modules (Folder containing installed npm modules) Here is the attempted solution: import subprocess import os dir_path = os.path.dirname(os.path.realpath(__file__)) # Retrieve the directory ...