Ahmad
Ahmad

Reputation: 4244

File upload inside JSON

I'm building a REST API Service using PHP. I know how to receive file in standard html form(multipart/form-data).

But in my service I want to use json. So the question is, how to upload file when the client use Content-Type:application-json? How to embed a file in JSON?

Or is there some other or standard way that I must follow regarding REST API design?

Upvotes: 0

Views: 1217

Answers (2)

Aurélien Bénel
Aurélien Bénel

Reputation: 3852

You'll have to encode your file as a string (e.g. in base64) and put this string in your JSON as a JSON value.

Upvotes: 2

diggersworld
diggersworld

Reputation: 13080

Looks like there's a few answers to this question already. See the following question:

How can i upload a file using jquery's $.ajax function with json and php

They largely suggest using a plugin.

Upvotes: 0

Related Questions