Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Read file from server HTML 5

Hey everyone,

I have a packaged HTML 5 project sitting on my server.

I'm trying to pull a text file from the server and parse it into a string array using code from Rama's BP library.

I have the same project packaged and working on Windows, but when I attempt to pull the file from the server it returns a null path. I'm assuming that has to do with the way FFileHelper is reading the file path, but I can't seem to find another way around this.

I've tried out LE's plugin series to properly request the files or read a JSON object rather than a text file. Unfortunately, all of the plugins cause build errors in blank projects all the way back to 4.13. All related to symbol definitions.

I'm still kinda sketchy when working in Unreal C++ so I was hoping to get some help pulling the file down. Everything I've done causes errors. Here's the code I'm using to parse the text file for reference.


 #pragma once
 #include "CoreMisc.h"
 #include "Kismet/BlueprintFunctionLibrary.h"
 #include "StandardBlueprintFunctions.generated.h"
 class PROGEN_API UStandardBlueprintFunctions : public UBlueprintFunctionLibrary
 /*Save String Array*/
     /** Saves multiple Strings to filename of your choosing, with each string on its own line! Make sure include whichever file extension you want in the filename, ex: SelfNotes.txt . Make sure to include the entire file path in the save directory, ex: C:\MyGameDir\BPSavedTextFiles */
     UFUNCTION(BlueprintCallable, Category = "BPStandardFunctions")
         static bool FileIO__SaveStringArrayToFile(FString SaveDirectory, FString JoyfulFileName, TArray<FString> SaveText, bool AllowOverWriting = false);
 /*Load String Array*/
         /** Loads a text file from hard disk and parses it into a String array, where each entry in the string array is 1 line from the text file. Option to exclude lines that are only whitespace characters or '\n'. Returns the size of the final String Array that was created. Returns false if the file could be loaded from hard disk. */
         UFUNCTION(BlueprintPure, Category = "BPStandardFunctions")
         static bool LoadStringArrayFromFile(TArray<FString>& StringArray, int32& ArraySize, FString FullFilePath = "Enter Full File Path", bool ExcludeEmptyLines = false);


 #include "Progen.h"
 #include "StandardBlueprintFunctions.h"
 bool UStandardBlueprintFunctions::FileIO__SaveStringArrayToFile(FString SaveDirectory, FString JoyfulFileName, TArray<FString> SaveText, bool AllowOverWriting)
     //Dir Exists?
     if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*SaveDirectory))
         //create directory if it not exist
         //still could not make directory?
         if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*SaveDirectory))
             //Could not make the specified directory
             return false;
     //get complete file path
     SaveDirectory += "\\";
     SaveDirectory += JoyfulFileName;
     //No over-writing?
     if (!AllowOverWriting)
         //Check if file exists already
         if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*SaveDirectory))
             //no overwriting
             return false;
     FString FinalStr = "";
     for (FString& Each : SaveText)
         FinalStr += Each;
         FinalStr += LINE_TERMINATOR;
     return FFileHelper::SaveStringToFile(FinalStr, *SaveDirectory);
 /** Load string array from file*/
 bool UStandardBlueprintFunctions::LoadStringArrayFromFile(TArray<FString>& StringArray, int32& ArraySize, FString FullFilePath, bool ExcludeEmptyLines)
     ArraySize = 0;
     if (FullFilePath == "" || FullFilePath == " ") return false;
     //Empty any previous contents!
     TArray<FString> FileArray;
     if (!FFileHelper::LoadANSITextFileToStrings(*FullFilePath, NULL, FileArray))
         return false;
     if (ExcludeEmptyLines)
         for (const FString& Each : FileArray)
             if (Each == "") continue;
             //check for any non whitespace
             bool FoundNonWhiteSpace = false;
             for (int32 v = 0; v < Each.Len(); v++)
                 if (Each[v] != ' ' && Each[v] != '\n')
                     FoundNonWhiteSpace = true;
             if (FoundNonWhiteSpace)
     ArraySize = StringArray.Num();
     return true;

Thanks for any help! Let me know if you need anything else.


Product Version: UE 4.15
more ▼

asked May 02 '17 at 06:17 AM in C++ Programming

avatar image

113 18 22 26

avatar image Entropikz May 02 '17 at 06:27 AM

I'm wondering if using IPlatformFile would be better than FFileHelper?

My server uses Unix based text file formatting. I figured this would just cause issues with symbols and formatting rather than invalidating the entire file, but could that cause the problem?

If so I could manually upload the files and run a script to change the format structure.

If anyone could offer up some insight on the build errors with the LE plugins that would be amazing as well. Reading the files as XML or JSON would be a lot easier for what I'm trying to do, but text files were the only thing I could think of...

My path formats were: /home/.../public_html/wp-content/progen/progenhtml5.html & www.sitename.com/wp-content/progen/progenhtml5.html

I'm using a GreenGeeks server too. I don't think that would have anything to do with this, but it might help.

Thanks again!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Do you mean you have a proper webserver set up?

You would be way better off just using webrequests and possibly Json to read the data properly. I am not sure why you are doing file stuff at all. I am assuming the files are on a different machine, so reading a file with a path will most likely fail anyway.

Here is a nice and short tutorial on how to set up WebRequests with Unreal Engine. It pretty much covers what you need to requests the file as string and then parse it into a JsonObject.

more ▼

answered May 04 '17 at 10:12 PM

avatar image

1.1k 31 12 47

avatar image Entropikz May 06 '17 at 03:24 AM

Hey Denny,

Thanks for the answer! I've been working on a procedural language generator that reads text files for dynamic language creation.

I know it's not really something Unreal is made for, but I wanted to see if it could be done and for Windows it can. Just more proof that Unreal is the best ;).

Everything is set up on the same server and everything is installed in the same directory so I don't think it's an issue with physical location, although I don't know enough about complex server configuration to know that for sure.

My original plan was to read JsonObjects, but the plugins for HTTP requests and JsonObjects cause HTML5 builds to fail in every engine build back to 4.13 so these tutorials are clutch.

I might as well grow some stones and get out of the blueprint editor now anyway. =P

I'm going to take a crack at some stuff tomorrow and I'll let you know how it goes.

Thanks again!


(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question