file_temp
host callCapy
function file_temp() string
Description
file_temp() creates a uniquely named empty file in the configured TMP_UPLOAD_PATH directory. Bearer deletes it when the request ends. Imported functions and components share that request lifetime. A task keeps its files until the task ends. A service handler keeps its files until that handler ends.
Use the returned path directly. Adding a suffix creates a different path that Bearer does not track. If you rename the file, the destination remains after cleanup. Cleanup removes a replacement file at the original path, but does not remove a directory placed there.
Return Values
The new empty file path. Returns "" on failure.
Example
Capy
var path := file_temp()
if path != "" {
file_put_contents(path, "scratch")
print(file_get_contents(path).value ?? "", "\n")
}
Output
scratch