savefiledialog Asynchronous
Ask the user where to save the supplied contents, then return a handle to the saved file. Use it for an export where the user chooses the destination. Prepare the text or binary contents before opening the dialog.
Luau
savefiledialog(contents: string, options: FileDialogOptions?) -> Document?Parameters
| Parameter | Type | Description |
|---|---|---|
contents | string | Contents as a Luau string. The string may contain text or binary bytes. |
options | FileDialogOptions? | Optional picker settings. Field names are case sensitive; see the options fields below. |
Argument fields
Luau
FileDialogOptions = {
defaultPath: string?, title: string?, extensionFilter: {string}?,
suggestedName: string?, defaultExtension: string?
}| Field | Description |
|---|---|
defaultPath | Initial picker location. The Android picker uses this only when it is a content:// URI. |
title | Optional chooser title for open dialogs. It is not used as the save filename. |
extensionFilter | Array of extensions, such as {"txt", "json"}. Known extensions are converted to MIME filters; unknown-only filters allow all types. Folder dialogs do not use this filter. |
suggestedName | Suggested filename for savefiledialog. Defaults to untitled when omitted or empty. |
defaultExtension | Extension appended to the suggested save filename when it does not already have that extension. Leading dots are removed. |
Returns
Document?The saved file as a Document, or nil if the user cancels the dialog.
Usage notes
suggestedName defaults to untitled. The contents argument must be a string; the dialog does not serialize tables for you.
Document is a handle returned by a file dialog or a folder method. Call its methods with a colon, for example document:Read(). After Delete succeeds, that handle is invalid and further method calls raise an error.
Example
Luau
local document = savefiledialog("Hello!", { suggestedName = "greeting.txt" })
if document then
print("Saved", document:GetName())
end