This resource for FiveM Servers lets you host media files directly on your server, eliminating the need to upload files to third-party websites.
FiveMMediaHost
folder in your resources
folderensure FiveMMediaHost
at the start, before other resources, in your server.cfg
[!WARNING] Always ensure to have enough disk space when using this resource!
[!IMPORTANT] If you place the resource in a subfolder (e.g.,
resources/[utils]/FiveMMediaHost
) yourImageDirectory
property would need to beConfig.ImageDirectory = "resources/[utils]/"..GetCurrentResourceName().."/images/"
[!NOTE] This resource currently supports:
- Images (webp/png/jpg)
- Audio (ogg/mp3/webm)
- Video (mp4/webm)
Note: Use webp and webm for faster loading and smaller files.
Config = {}
Config.UseCFXReDomain = true -- Use your server's CfxX.re domain? (Recommended true)
Config.ServerHost = "http://127.0.0.1:30120/"..GetCurrentResourceName() -- Or you can replace it with your custom domain name/IP address
Config.IDLength = 30 -- Image name length
Config.MediaEndpoint = 'media' -- The endpoint from where you can get media files
Config.ImageDirectory = "resources/"..GetCurrentResourceName().."/images/"
Config.SoundDirectory = "resources/"..GetCurrentResourceName().."/sounds/"
Config.VideoDirectory = "resources/"..GetCurrentResourceName().."/videos/"
Config.ImageUploadURL = exports.FiveMMediaHost:getUploadServer()
screenshot-basic
local imageUploadPromise = promise.new()
exports['screenshot-basic']:requestScreenshotUpload(Config.ImageUploadURL, 'image', { ['encoding'] = 'webp' }, function(uploadResponse)
if not uploadResponse then imageUploadPromise:resolve(nil) return
local responseJson = json.decode(uploadResponse)
imageUploadPromise:resolve(responseJson and responseJson.attachments[1].proxy_url)
end)
local uploadedImageUrl = Citizen.Await(imageUploadPromise)
In this repository I created, you can test how to send audio to the script: https://github.com/GasparMPereira/HTML-Microphone-Recorder
In this repository I created, you can test how to send video to the script: https://github.com/GasparMPereira/HTML-Camera-Recorder
https://your_cfx_re_domain/FiveMMediaHost/upload
https://your_cfx_re_domain/FiveMMediaHost/media/your_media_file_id.extension
Please submit an Issue, if you have any suggestions/bugs. And also a Pull Request if you would like to contribute with some code. All help is welcome!
Copyright (C) 2024 - Gaspar Pereira