File upload handling in RESTful Symfony apps

3,247 views
Skip to first unread message

Stepan Anchugov

unread,
Jul 8, 2014, 11:56:36 AM7/8/14
to resting-wi...@googlegroups.com
How do you handle file uploads in your APIs?

Imagine we have an endpoint that expects some data and some embedded files (for example, the Twitter's POST statuses/update_with_media).

Twitter's API usually expects JSON, but this exact method expects raw multipart data. It seems like an inconsistency to me. The other way around would be putting the (Base64-)encoded media into the JSON, and it seems pretty ugly too.

Also, we could set up an endpoint that would accept only uploads and give back IDs we could then somehow link to created models (that means we'd have two methods: one for media upload and one for the data).

What's the right way here? And how do we do this with FOSRest?

evil...@gmail.com

unread,
Jul 8, 2014, 12:15:20 PM7/8/14
to resting-wi...@googlegroups.com
We just did raw mutipart data.  So, if you wanted to send something without a file, it would accept JSON/XML - but if you wanted to send a file, then multipart with the extra "file" field.

One thing that we did was add our own custom Deserializer that accepts arrays, so we still use the JMS Serializer for decoding even raw POST data (which excludes the file, of course).  So our logic doesn't care what the input format is - it just checks the request to see if it included any files.

The inconsistency bothers me too, still - but I couldn't think of another really practical way.

Fernando Arconada

unread,
Jul 8, 2014, 3:24:19 PM7/8/14
to resting-wi...@googlegroups.com
I did it with Base64 encoded in the JSON

evil...@gmail.com

unread,
Jul 8, 2014, 3:29:50 PM7/8/14
to resting-wi...@googlegroups.com
I did it with Base64 encoded in the JSON

Got a couple questions if you don't mind:

* How did it turn out?
* Were you sending large files?
* What were the clients of the API?  If they were traditional web browsers, were there cross-platform issues?

Malachi Soord

unread,
Jul 11, 2014, 2:35:14 AM7/11/14
to resting-wi...@googlegroups.com
Saw an interesting post about this online which although not Symfony related explains two options that are available.


The project I am working on will need to implement image uploads and we are going to handle it via multipart/form-data.

Has anyone tried using BSON with Symfony?

Bezalel Hermoso

unread,
Jul 23, 2014, 7:50:35 PM7/23/14
to resting-wi...@googlegroups.com
I have implemented a file upload endpoint which simply accepts the raw multi-part data submitted. We also expect the client to specify a "Content-type" header to the mime-type of the submitted file. So all we had to do was write the raw data to a file and save it with the appropriate extension (using ExtensionGuesser).

Di majo

unread,
May 8, 2024, 12:23:54 PM5/8/24
to RESTing with Symfony
MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
LOAN DEAL
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA
UNIONPAY RECEIVER

Thanks.


NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT.

DM ME ON WHATSAPP
+44 7529 555638
Reply all
Reply to author
Forward
0 new messages