1

I want to return a JSON response from my REST API as well as a file.

So the json will include metadata about the file and the return also the file itself within the same http response.

Is this something that can be done in PHP and if so does someone have a simple example to help me?

Michael
  • 1,769
  • 2
  • 12
  • 21
  • 2
    You can't really return a restful response, including a file. IMO, return the file path in the restful response, and have the script make another call to fetch the file. – Blue Oct 21 '18 at 15:49
  • This was the last option I was going use. I remember seeing a method of doing this in SOAP but wasn’t sure if there was a way to do this using REST – Michael Oct 21 '18 at 16:08
  • You would need to encode the file in some way - base64 would be a good starting point. Then you can send it as string data, and re-convert on the client end. Check this out - https://stackoverflow.com/questions/34485420/how-do-you-put-an-image-file-in-a-json-object/34485762 – ivanivan Oct 21 '18 at 16:25
  • Just read about Multipart/related content type, can I use this – Michael Oct 22 '18 at 13:45

0 Answers0