Search code examples
asynchronousluawaffle

Synchronous file save in lua waffle


I have a waffle lua web application and I need to process submitted video file using some command-line tools.

The problem is that a call to save function on req.form.file is asynchronous so execution proceeds before the file is actually saved.

req.form.file:save{path=path}

When I call command line tool ffprobe on that path I get errors indicating invalid data. Using the same command in console works as expected.

My guess is that the file is not yet saved when a call to ffprobe is executed.

Is there a way to ensure the file is written to disk before proceeding with further commands in lua waffle app?


Solution

  • I've found a way to do it, instead of using asynchronous method provided by waffle module, I've used build in lua io module that does the job synchronously:

    local out = assert(io.open(path, "wb"))
    out:write(req.form.file.data)