Download a file to hard drive (Blueprints or C++)

Is there a method in the engine that will download a file from the web to the game folder?

Not direcly, UE4 got API for HTTP, but you need to manually dump content bytes (and you can access them via this https://docs.unrealengine./latest/INT/API/Runtime/HTTP/Interfaces/IHttpBase/GetContent/index.html , if it’s a text file thats even easier https://docs.unrealengine./latest/INT/API/Runtime/HTTP/Interfaces/IHttpResponse/GetContentAsString/index.html) in to the file in order to get downloaded file via HTTP on harddrive. Practically only thing HTTP does is download on demend, in case of webpages it downloads and process it in same time, so it everything works the same for any kind of data. Here you got API refrence for whole HTTP module:

https://docs.unrealengine./latest/INT/API/Runtime/HTTP/index.html

Here you got simple example how to do HTTP requests, search “HTTP” in UE4 github for more examples:

https://github./EpicGames/UnrealEngine/blob/ab9713f2c0346236b0fdd271d3304cf0991d23de/Engine/Source/Runtime/Online/HTTP/Private/HttpTests.cpp

Remeber to add “HTTP” module dependies in your build script of your game code module, same as you do with “AIModule” for AI stuff

It’s also good to learn how HTTP works when you using it:

if you ever played with php or any other web scripting you should already have idea how HTTP works, the interaction is the same just you in client side this time

Hello ,

Can this method also work for a mobile app?
Thank you.

@so2gamemake Yes, it can. I’ve just used it on Android. The only problem I had was on saving the downloaded content to a file. I had to be sure the target folder existed. I did it by using this function.

In general most APIs that UE4 wraps work on all platfroms that UE4 supports, still there is some cases of some things not working on some platfrom

Just found a problem. Trying to download a 42MB mp4, the download stops at random amounts. Usually between 10 and 26MB downloaded. And it doesn’t fire any events. Just stops firing the progress one.

EDIT: Solved

I was calling the download from an UObject created at runtime and it was getting garbage collected before the download completed. Looking at Engine\Source\Runtime\UMG\Private\Blueprint\AsyncTaskDownloadImage.cpp I saw that Epic adds the downloader class to root (AddToRoot()) when download starts and removes it after it’s finished (RemoveFromRoot()). And it solved it for me.

How to get some of the resources in Pak?

I’ve researched it also and found this to be a very useful thread.

Can any of you guys possibly share some code for the MP4 download and save ?
cheers Dunk

Hi, Dunk!

Here’s the class I’ve made for downloading files from an URL. It won’t compile out of the box. You need to replace ProjectName.h on the .cpp with your project’s main Header and PROJECTNAME_API on the .h with your project’s API name.

Also, in your Project’s [ProjectName].Build.cs you need to add “HTTP” to the PublicDependencyModuleNames.

Cheers, Rodrigo.

Dude you are STAR !
…will check that our right now…

hi. were you having crash when download was stopping?
bcz my app is keep crashing.

THANK YOU. I was going crazy, i forgot to add mine as well, but tried to add a break point to the destructor, and lo and behold. it’s being removed.

Does this expose to blueprints? I have it compiled ok but I can’t find the node via blueprints

Yes, it does. Call MakeDownloader then use its return value to call DownloadFile.

Thanks for the quick reply - I’ve compiled but there is still no node. I’m using a blueprint project with C++ classes from a source code built engine 4.17.2.

To get it to compile I’m having to put {#include “FileDownloader.h”} above {#include projectname.h} (i’ve renamed it to my proj name) and having to add “#include “PlatformFilemanager.h””.

Any thoughts? Is this useable in a blueprint project? I’ve tried searching the category and several combinations of download and what not. Even tried across different blueprint types.

I finally got this working - I had to remove:

"#include gamename.h"

from the .cpp file and add the following:

#include "Misc/Paths.h"
#include "HAL/PlatformFilemanager.h"

In addition I didnt realize I had my VS set to development server (I had recently been making a dedicated server). It needed to be development editor.

bOI YES YOU CAN

Meh idk how but you can :)

https://www.unrealengine./marketplace/en-US/product/runtime-files-downloader
download this plugins