I would need to upload an image from the application, that I'm developing, to the server and I would like to know how I can develop the Multipart Request to load the image using Google Volley.
Thanks
I would need to upload an image from the application, that I'm developing, to the server and I would like to know how I can develop the Multipart Request to load the image using Google Volley.
Thanks
I have an example to upload images by
Google Volley
. Take a look:And you can use it like this:
I hope these codes will inspire you.
I copied this class from https://gist.github.com/ishitcno1/11394069 I will show you how you use it. It worked in my case. Copy this class. Make necessary changings.
And here this is the method to upload image.
How are you gonna get filePath
Finally define this in your activity,
Important part, this is PHP code for your server,
You should make sure to send your file in this method,
and pay attention this,
is used in PHP code to indicate image file. I guess this way, you can send any file. Sorry for my poor explanations, I tried to explain everything.
@silverknight's answer works, however, I also had to add the following in
build.gradle
to resolvehttpcomponents
dependencies:NOTE: Don't use org.apache.httpcomponents:httpclient
You should avoid using the standard version of
'org.apache.httpcomponents:httpclient:4.5.2'
If you try:
you will get:
or something similar to the existing comments [1] [2] [3].
You should rather use the Android port of
httpclient
, as per this SO answerNOTE: Use org.apache.httpcomponents:httpmime:4.3.6
You have to use
org.apache.httpcomponents:httpmime:4.3.6
, you cannot go above version4.3.x
. For example, you may be tempted to use the latest version ofhttpmime
, which at the time of writing is 4.5.2:with this config, you will get the following when you invoke
PhotoMultipartRequest
: