This resource for FiveM Servers lets you host media files directly on your server, eliminating the need to upload files to third-party websites.
- Paste the
FiveMMediaHost
folder in yourresources
folder - Add
ensure FiveMMediaHost
at the start, before other resources, in yourserver.cfg
- Start the server and that's all
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
) your ImageDirectory
property would need to be Config.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()
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
- Copy your Cfx.re server URL, from the server console
- Paste it in your script as
https://your_cfx_re_domain/FiveMMediaHost/upload
- You can then get the images like so:
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