7

Why or when should someone use Multipart/form-data?

the thing is I use to upload images to server with httpost base64 (random example) but I noticed while reading through volley I Can upload file with multipart/form-data ..

So when should I use consider to upload my images to server ? multipart or httpost base64

Cœur
  • 37,241
  • 25
  • 195
  • 267
Moudiz
  • 7,211
  • 22
  • 78
  • 156
  • You cannot compare a post method with an encoding type. Your question does not make sense. – greenapps Jul 31 '15 at 08:52
  • @greenapps I meant with base64 I use httpost , but multipart I use different way .. which is better – Moudiz Jul 31 '15 at 09:03
  • What kind of different way? Come to the point please. – greenapps Jul 31 '15 at 10:22
  • @greenapps what is multipart when I should use it ? – Moudiz Jul 31 '15 at 11:10
  • It is better to show your code for the two 'ways'. Then we can compare. – greenapps Jul 31 '15 at 15:03
  • @greenapps I couldnt test the multipart because I have to download appache librarry , however I have added 2 links explaining about multipart and httpost and I want to knwo what is multipart and if its needed yo use it – Moudiz Jul 31 '15 at 15:25
  • Sorry i did not reed those links and i will not. Please explain your problem without links. – greenapps Jul 31 '15 at 15:32
  • @Greenapps what is multipart and when i have to use it ? I use httpost with base64 .. should i start to learn multipart because maybe better or faster ? Thats my problem – Moudiz Jul 31 '15 at 15:34

1 Answers1

3

Multipart is multi part (duh).

So if you have a very large file the request will send it in multiple parts instead of inside a "regular" POST request. Since POST requests also have an upper limit, which now I don't remember but its not that much (a couple of megabytes) if you upload something huge you should use multipart-forms if you use http.

breakline
  • 5,776
  • 8
  • 45
  • 84
  • So If I am using small images , then i keep using httpost with base64 conversation right ? – Moudiz Jul 31 '15 at 09:28
  • Also note that POST itself is (should be) limitless, but you can set up a limit on any server. – breakline Jul 31 '15 at 09:28
  • 1
    Well you can, but also base64 encoding-decoding can cause alot of overhead as its rather slow. – breakline Jul 31 '15 at 09:29
  • what do you suggest to use to convert the image? – Moudiz Jul 31 '15 at 09:55
  • " Multipart has nothing to do with file upload." yes it does. Multpart/form-data is applied to a form though, so you can send everything in a multi-part form, including "regular" data. – breakline Jul 31 '15 at 10:26
  • I pretty much assumed that everyone in this thread knows whats the connection between file-upload and multipart forms. – breakline Jul 31 '15 at 15:10
  • Yes can be. But that is offtopic. You were asked to explain what a multipart form had to do with files. You still did not aswer that. – greenapps Jul 31 '15 at 15:18
  • Pretty much multipart forms is the standard way to upload files and its been used by millions of people like that. Whats your point again? It sounds like you don't understand something here. – breakline Jul 31 '15 at 15:27
  • Yes they can be used to upload files. But it is still multipart even if you do not upload files. Is you only send some parameters. A multi part form or multi part form data is mostly used not uploading files. So your first remark that the name multi part came from uploading files in multi/many parts is still not true. That's why i called it nonsense. – greenapps Jul 31 '15 at 15:38
  • And I never said you can ONLY use it for file uploads. But its a fact that IF you use file upload via a file input, you HAVE TO use multipart forms. SOmehow you misunderstand the point of these posts, I'm not here to argue you about something you misinterpret, I'm here to answer OP's question which was about FILE UPLOAD. Why not arguing about writing your own protocol then? Maybe read OP's post again and what I answered. – breakline Jul 31 '15 at 15:41
  • And maybe read about the actual specification of what "mutlipart" really means and why I wrote what I wrote: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4 – breakline Jul 31 '15 at 15:43