1- # ScreenCapture (WIP)
1+ # ScreenCapture
22
33ScreenCapture is a being built as a replacement for screenshot-basic in FiveM.
44
@@ -17,7 +17,7 @@ Converting Base64 to Blob/Buffer is easy enough with Node, but Lua ScRT in FiveM
1717### serverCapture (server-side export)
1818
1919| Parameter | Type | Description |
20- | ------------ | -------------------------- | --------------------------------------------------------------------------- |
20+ | ---------- | ------------------------ | ------------------------------------------------------------------------- |
2121| ` source ` | string | Player to capture |
2222| ` options ` | object/table | Configuration options for the capture |
2323| ` callback ` | function | A function invoked with the captured data |
@@ -27,13 +27,12 @@ Converting Base64 to Blob/Buffer is easy enough with Node, but Lua ScRT in FiveM
2727
2828The ` options ` argument accepts an object with the following fields:
2929
30- | Field | Type | Default | Description |
31- | --------------| -----------------| ----------| --------------------------------------------------------------------------|
32- | ` headers ` | ` object/table ` | ` null ` | Optional HTTP headers to include in the capture request. |
33- | ` formField ` | ` string ` | ` null ` | The form field name to be used when uploading the captured data. |
34- | ` filename ` | ` string ` | ` null ` | Specifies the name of the file when saving or transmitting captured data.|
35- | ` encoding ` | ` string ` | ` 'webp' ` | Specifies the encoding format for the captured image (e.g., ` 'webp' ` ). |
36-
30+ | Field | Type | Default | Description |
31+ | ----------- | -------------- | -------- | ------------------------------------------------------------------------- |
32+ | ` headers ` | ` object/table ` | ` null ` | Optional HTTP headers to include in the capture request. |
33+ | ` formField ` | ` string ` | ` null ` | The form field name to be used when uploading the captured data. |
34+ | ` filename ` | ` string ` | ` null ` | Specifies the name of the file when saving or transmitting captured data. |
35+ | ` encoding ` | ` string ` | ` 'webp' ` | Specifies the encoding format for the captured image (e.g., ` 'webp' ` ). |
3736
3837``` ts
3938RegisterCommand (
@@ -57,39 +56,50 @@ RegisterCommand(
5756
5857### remoteUpload (server-side export)
5958
60- | Parameter | Type | Description |
61- | ------------ | -------------------------- | --------------------------------------------------------------------------- |
62- | ` source ` | string | Player to capture |
63- | ` url ` | string | The upload URL |
64- | ` options ` | object/table | Configuration options for the capture |
65- | ` callback ` | function | Callback returning the HTTP response in JSON |
66- | ` dataType ` | string (default: base64) | What data type should be used to upload the file: ` 'base64' ` or ` 'blob' ` |
59+ | Parameter | Type | Description |
60+ | ---------- | ------------------------ | ------------------------------------------------------------------------ |
61+ | ` source ` | string | Player to capture |
62+ | ` url ` | string | The upload URL |
63+ | ` options ` | object/table | Configuration options for the capture |
64+ | ` callback ` | function | Callback returning the HTTP response in JSON |
65+ | ` dataType ` | string (default: base64) | What data type should be used to upload the file: ` 'base64' ` or ` 'blob' ` |
6766
6867#### Options
6968
7069The ` options ` argument accepts an object with the following fields:
7170
72- | Field | Type | Default | Description |
73- | -------------- | ----------------- | ---------- | -------------------------------------------------------------------------- |
74- | ` headers ` | ` object/table ` | ` null ` | Optional HTTP headers to include in the capture request. |
75- | ` formField ` | ` string ` | ` null ` | The form field name to be used when uploading the captured data. |
76- | ` filename ` | ` string ` | ` null ` | Specifies the name of the file when saving or transmitting captured data.|
77- | ` encoding ` | ` string ` | ` 'webp' ` | Specifies the encoding format for the captured image (e.g., ` 'webp' ` ). |
71+ | Field | Type | Default | Description |
72+ | ----------- | -------------- | -------- | ------------------------------------------------------------------------- |
73+ | ` headers ` | ` object/table ` | ` null ` | Optional HTTP headers to include in the capture request. |
74+ | ` formField ` | ` string ` | ` null ` | The form field name to be used when uploading the captured data. |
75+ | ` filename ` | ` string ` | ` null ` | Specifies the name of the file when saving or transmitting captured data. |
76+ | ` encoding ` | ` string ` | ` 'webp' ` | Specifies the encoding format for the captured image (e.g., ` 'webp' ` ). |
7877
7978``` ts
80- RegisterCommand (" remoteCapture" , (_ : string , args : string []) => {
81- exp .screencapture .remoteUpload (args [0 ], " https://api.fivemanage.com/api/image" , {
82- encoding: " webp" ,
83- headers: {
84- " Authorization" : " " ,
85- }
86- }, (data : any ) => {
87- console .log (data );
88- }, " blob" )
89- }, false );
79+ RegisterCommand (
80+ ' remoteCapture' ,
81+ (_ : string , args : string []) => {
82+ exp .screencapture .remoteUpload (
83+ args [0 ],
84+ ' https://api.fivemanage.com/api/image' ,
85+ {
86+ encoding: ' webp' ,
87+ headers: {
88+ Authorization: ' ' ,
89+ },
90+ },
91+ (data : any ) => {
92+ console .log (data );
93+ },
94+ ' blob' ,
95+ );
96+ },
97+ false ,
98+ );
9099```
91100
92101## Lua example with ` remoteUpload `
102+
93103``` lua
94104exports .screencapture :remoteUpload (args [1 ], " https://api.fivemanage.com/api/image" , {
95105 encoding = " webp" ,
@@ -101,8 +111,27 @@ exports.screencapture:remoteUpload(args[1], "https://api.fivemanage.com/api/imag
101111end , " blob" )
102112```
103113
114+ ## Screenshot Basic compatibility
115+
116+ ### This is NOT recommend to use, as you risk expsoing tokens to clients.
117+
118+ ### requestScreenshotUpload (client-side export)
119+
120+ ``` lua
121+ exports [' screencapture' ]:requestScreenshotUpload (' https://api.fivemanage.com/api/image' , ' file' , {
122+ headers = {
123+ [" Authorization" ] = API_TOKEN
124+ },
125+ encoding = " webp"
126+ }, function (data )
127+ local resp = json .decode (data )
128+ print (resp .url );
129+ TriggerEvent (' chat:addMessage' , { template = ' <img src="{0}" style="max-width: 300px;" />' , args = { resp .url } })
130+ end )
131+ ```
104132
105133## What will this include?
134+
1061351 . Server exports both for getting image data and uploading images/videos from the server
1071362 . Client exports (maybe)
1081373 . Upload images or videos from NUI, just more secure.
0 commit comments