How so, exactly?
It is just a string field, JSON doesn't care what its content is. When you get the string back, simply parse it to extract the base64 substring after the comma, and then decode that substring to get the raw bytes that you can then save to a file. IOW, just reverse the code that created the string. For example:
procedure Base64ToImage(const Base64String, FilePath: string);
var
FileStream: TFileStream;
Bytes: TBytes;
begin
Bytes := TNetEncoding.Base64.DecodeStringToBytes(Base64String);
FileStream := TFileStream.Create(FilePath, fmCreate);
try
FileStream.WriteBuffer(Pointer(Bytes)^, Length(Bytes));
finally
FileStream.Free;
end;
end;
procedure LoadBase64JsonToImage;
var
JSONObject: TJSONObject;
Base64String: string;
JSONString: string;
JSONFile: TStringList;
begin
JSONFile := TStringList.Create;
try
JSONFile.LoadFromFile('image_base64.json');
JSONString := JSONFile.Text;
finally
JSONFile.Free;
end;
JSONObject := TJSONObject.ParseJSONValue(JSONString) as TJSONObject;
try
JSONString := JSONObject.GetValue('image_data').Value;
finally
JSONObject.Free;
end;
Base64String := Copy(JSONString, Pos(',', JSONString)+1, MaxInt);
Base64ToImage(Base64String, 'path/to/image.jpg');
end;
You are not supposed to save the entire string to a file. Just as the string wasn't produced entirely from a file to begin with, but from a text and a file.