Reading a file online
I need to read a sequence of bytes stored in a basic txt file which can be found at a specific url. With a local file path I can use SaveFileToArray() function to store the bytes in a uint8 array, how can I do the same with the given file url?
asked Oct 29 '15 at 03:48 PM in C++ Programming
Fact that you can use http urls as files is a extra feature to make things comfitible, but in code they are 2 separate data channels with diffrent APIs.
UE4 has module to talk to HTTP server:
This is entry point:
Create a http request:
I returns request body which you can edit with those functions:
Request is processed asynchronously so it does not lock the thread waiting for response from server, thats why you need to bind event which be called when responce been recived:
Once you set up the request you call ProcessRequest and HTTP module with do the rest:
And once it got reponce it will call function you binded with IHttpReponce argument from which you can read reponce data:
Here you have nice simple example from engine source code how to use it (Note how OnProcessRequestComplete function arguments, your function needs to be exactly the same, only name can be different):
If you don't know how HTTP works (which if you ever worked with PHP and web devlopment you should know) then learn about it because it will be very useful here:
And lastly if you gonna use HTTP module, remember to add "HTTP" in to depency in build scipt same as you do with "AIModule", otherwise you gonna have linker errors
Follow this question
Once you sign in you will be able to subscribe for any updates here