So I'm receiving documents via a REST api GET request that returns JSON containing the files as base64 encoded data along with metadata about the file such as filename and description.
Here is an example of the JSON being returned (real base64 data replaced with "BASE64 ENCODED FILE" for readability):
"documents":[
{
"name":"Job Description.doc",
"description":"Job Description",
"data":"BASE64 ENCODED FILE"
},
{
"name":"Person Description.doc",
"description":"Person Description",
"data":"BASE64 ENCODED FILE"
}
]
I know I can json_decode()
the data, then do:
file_put_contents('/path/to/file/'.base64_decode($documents->data));
The problem with this is that the file is then permanently stored (which is not acceptable in this case). I would like to know if there is any way to offer the file for download without storing it as a file anywhere. Perhaps in a similar way to how a base64 encoded image can be used as the source for an image tag.
What are your thoughts? Can this be done?