Code Monkey home page Code Monkey logo

fivemmediahost's Introduction

FiveMMediaHost

Discord

This resource for FiveM Servers lets you host media files directly on your server, eliminating the need to upload files to third-party websites.

Installation

  1. Paste the FiveMMediaHost folder in your resources folder
  2. Add ensure FiveMMediaHost at the start, before other resources, in your server.cfg
  3. 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.

Configuration Settings

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/"

Usage Instructions

How to pass the Upload URL to an encrypted resource

Config.ImageUploadURL = exports.FiveMMediaHost:getUploadServer()

Usage example with 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)

How to Upload Audio

In this repository I created, you can test how to send audio to the script: https://github.com/GasparMPereira/HTML-Microphone-Recorder

How to Upload Video

In this repository I created, you can test how to send video to the script: https://github.com/GasparMPereira/HTML-Camera-Recorder

How to pass the server's URL to a resource that needs it in text format

  1. Copy your Cfx.re server URL, from the server console cfx_re_domain
  2. Paste it in your script as https://your_cfx_re_domain/FiveMMediaHost/upload
  3. You can then get the images like so: https://your_cfx_re_domain/FiveMMediaHost/media/your_media_file_id.extension

Contributing

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

fivemmediahost's People

Contributors

gasparmpereira avatar viruxe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.