Jump to content

Send files from server to client using fetchRemote


Artix

Recommended Posts

Posted
		
		
	 function myCallback(data, errno,path)  
               if errno == 0 then  
               triggerEvent("onFileTDownload", root, "sound.mp3", data);  
		  else
              outputChatBox ('Error  '..errno)	--it return error 7, when ip == localhost returns error 1006	  
	        end		   
			   
         end	
		
		
      addEvent("onFileTDownload", false);  
      addEventHandler("onFileTDownload", root, 
              function(path,data)  
                    local file;  
                    if not fileExists(path) then file = fileCreate(path);  
                    else file = fileOpen(path); end;  
                    fileWrite(file, data);  
                    fileClose(file);                    
  
                    -- do whatever with the file ...  
              end);  
  
  function testdownload ()
    fetchRemote("http://127.0.0.1:80/testressource/sound.mp3",myCallback, "", false,':testressource/sound.mp3');  
  --[[i tried the following two examples too...
    fetchRemote("http://localhost/testressource/sound.mp3",myCallback, "", false,':testressource/sound.mp3'); 
    fetchRemote("http://localhost:80/testressource/sound.mp3",myCallback, "", false,':testressource/sound.mp3'); ]]
  end	
addCommandHandler ('tts',testdownload)  

--[[ All in the client side]]

How to solve it?

can someone help me pls

  • Moderators
Posted
6 minutes ago, Artix said:

How to solve it?

can someone help me pls

It is not as if players can download every file from the server. If they could, they would be able to steal all your stuff.

You need to serve the file first with a webserver. Read: https://wiki.multitheftauto.com/wiki/Resource_Web_Access

<html src="sound.mp3" raw="true" />

 

  • Like 1

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...