Screenshots and Uploads
Take screenshots of a player's screen and upload files from your own scripts.
Screenshots go from the player's game straight to the media service, never through FXServer. They need screencapture or screenshot-basic started before this script. Every file shows on the Media page. All exports are listed on Exports.
A player's screen, from the server
local result, reason = exports["tgiann-fivem-stats-script"]:TakeServerImage(targetId, { reason = "report" })
if result then
print(result.url)
else
print("screenshot failed: " .. reason)
endThe player whose screen it is becomes the file's player. It waits up to Screenshot timeout (Settings > Players and items, 15 seconds by default).
From the client
local result, reason = exports["tgiann-fivem-stats-script"]:TakeImage({ reason = "bug report" })A player may start Player screenshots per minute (Settings > Players and items, 6 by default, 0 turns client screenshots off). The client cannot set the folder, the player or keep forever.
Upload a file from the server
local file = exports["tgiann-fivem-stats-script"]:UploadBase64(base64, {
filename = "house_12.webp",
path = "housing/photos",
metadata = { playerSource = source },
retentionExempt = true,
})
print(file.url) -- https://media.yourserver.com/f/housing/photos/house_12.webpJavaScript scripts can send a Buffer with UploadImage(buffer, { fileName, path, metadata }).
File names and fixed addresses
With a filename
<public address>/f/<path>/<filename>
The same folder and name replaces the file; the address stays the same
Without a filename (screenshots, upload links)
<public address>/f/<path>/<id>.webp
Always a new file
With a name you can build the address yourself and open it from anywhere, like Fivemanage.
Images are converted to WebP, so
house_12.pngbecomeshouse_12.webp. Letters, digits,_,-and.are kept, upper case too; other characters become-.A replaced file is checked again by browsers, so the new picture shows without adding
?v=to the address.Moving a named file to another folder in the panel changes its address to the new folder. Its id address (
/f/<id>.webp) never changes.GetFileandDeleteFileaccept the id, the address or<path>/<filename>.
A single-use upload link
Give the link to a NUI or a client. It accepts one file of that type (image, video or audio), sent as a multipart form field named file. The uploader cannot change the folder, the metadata or keep forever, and the file always gets its own id: a player can never replace a file by its name.
Every upload answers:
Folders, players and keep forever
path
The folder on the Media page, for example mdt/evidence
metadata.playerSource
The player the file belongs to. Their identifiers and character are added, so the Media page shows the name and can filter by player
metadata.targetSource
A second player the file is about (the reported player, the victim)
retentionExempt = true
Keep forever: never removed by the media retention in Settings > Media storage
Metadata keys starting with _ are reserved for the server and are dropped when they come from a client.
Scripts written for fmsdk
The resource provides fmsdk and uses the same export names, so scripts written for fmsdk work without changes. Remove the fmsdk resource itself.
Test it
Run /mediatest in game as an admin, see Admin Commands.