I'm using Symfony2 to build a web application and provide an API in JSON form to an Android application. Every thing is fine but now we (the Android developer and me) want our system to manage file upload like the user use the android application (from his mobile phone) to upload a file on the server side where Symfony2 is working and we don't know whether the upload sript should be done on client side (within the android application) or on the server side (within the symfony2 code). For now I think that all should be done on client side: all I've to do is to give to the android developer the URL where the file should be deposited and an API with JSON in order to recieve only the name of the file (in string format)... am I not right ?
Asked
Active
Viewed 402 times
2 Answers
1
The other solution is transforming the file into a base64 then send it through json, the server side having to save it either on disk or in database. To get the file, you can also transform it into a base64 and send back to the android app to reconsituate the original file.

Ciaran
- 11
- 1
0
Please take a look at this question How can I add an image file into json object?
When handling the JSON, you can store the file in your DB as BLOB or do something else in your Symfony application.

Community
- 1
- 1

Victor Sanchez
- 960
- 2
- 12
- 26
-
all my problem is about how to move this file physically from the mobile app to a specific location on the server but I don't use the BLOB method. Now the scrip that should move the file ... where is it suppose to be located on android or server side – Saint - Cyr MAPOUKA Dec 18 '15 at 16:47
-
On the [link](http://stackoverflow.com/questions/8726400/how-can-i-add-an-image-file-into-json-object) I provided, the answer explains how to put all the bytes from a File into a JSON object. – Victor Sanchez Dec 18 '15 at 16:51
-
ok so if I get you well it means that everything is doing on the android application ? – Saint - Cyr MAPOUKA Dec 18 '15 at 16:58
-
Well, that's one way to handle it if you already got the File in your android app and want to use JSON. See also [How to send a file in Android from mobile to server using http?](http://stackoverflow.com/questions/4126625/how-to-send-a-file-in-android-from-mobile-to-server-using-http) – Victor Sanchez Dec 18 '15 at 17:02
-
Another way would be to send only the file via socket [Transfer file from android to pc using socket programming](http://stackoverflow.com/questions/27283474/transfer-file-from-android-to-pc-using-socket-programming). Sending it via sockets would require more work and using something like [Gos Web Socket Bundle](https://github.com/GeniusesOfSymfony/WebSocketBundle) to handle the socket. – Victor Sanchez Dec 18 '15 at 17:05
-
Please notice that we're two developers working on the project (web app and native mobile app) and we where confuse as I think that's not my matter to handle the uploading of the file (move it physically ) but my collegue one (the android developer) and by all the answer you give I understand that I'm right. – Saint - Cyr MAPOUKA Dec 18 '15 at 17:10
-
If the File is on the Android device, then you are right, your colleague should handle it and send it to you, so you can do what you need to do with the file (store it in your server, for example). He should handle the file on the Android app, but you also need to write code on your server side to receive it. – Victor Sanchez Dec 18 '15 at 17:21
-
...but if you say "but you also need to write code on your server side to receive it" I don't understand at all because we communicating through API by using JSON and all I need is give him the URL of the folder where the file should be deposited so that I can do what ever I want and at that point I know how to do it but what php scrip should I write to "RECEIV" the file ?? or what do you explain by "RECEIVE" ?? – Saint - Cyr MAPOUKA Dec 18 '15 at 17:33
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/98365/discussion-between-victor-sanchez-and-saint-cyr-mapouka). – Victor Sanchez Dec 18 '15 at 17:34