473,506 Members | 17,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to upload multiple images with other data to server from android in one request?

1 New Member
Hi,

I want to upload multiple images selected from gallery and upload it to server along with other data.
Other data will be inserted into database in server.
Till now what i have done is firing http url in a for loop till number of images. All images are getting uploaded.

But, problem is, so many times the data also have been inserted into table.
What I want is, to insert data only once and upload number of images selected into a folder in server.

JAVA code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. HttpClient client = new DefaultHttpClient();
  3. HttpPost post = new HttpPost(URL)
  4.  
  5. try
  6. {    
  7.         MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
  8.         entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
  9.         entityBuilder.addTextBody("a", "apple");
  10.         entityBuilder.addTextBody("b", "banana");
  11.         entityBuilder.addTextBody("c", "cake");
  12.  
  13.         for (String element : list) {
  14.         File bin = new File(element);
  15.         FileBody bin1 = new FileBody(bin);                    
  16.         entityBuilder.addPart("ImageEncoded",bin1 );
  17.         HttpEntity entity = entityBuilder.build();
  18.         post.setEntity(entity);
  19.         response = client.execute(post);        
  20.         }    
  21.         httpEntity = response.getEntity(); 
  22.         result = EntityUtils.toString(httpEntity);
  23. }
  24.  

PHP code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php 
  3.  
  4.     $target_path1 = "uploads/";
  5.     $a = $_POST['a'];
  6.     $b = $_POST['b'];
  7.     $c = $_POST['c'];   
  8.     $fname = $_FILES['ImageEncoded']['name'];
  9.  
  10.     $query1 = mysql_query("INSERT INTO demo VALUES('','$a','$b','$c','$fname')");
  11.  
  12.     $target_path1 = $target_path1 . basename( $_FILES['ImageEncoded']['name']);
  13.     if(move_uploaded_file($_FILES['ImageEncoded']['tmp_name'], $target_path1)) {
  14.         echo "Success";
  15.  
  16.     } else{
  17.         echo "Fail";
  18.     }
  19.  
  20. ?>
  21.  
  22.  
May 2 '14 #1
4 18884
meditation
13 New Member
There is no way, you can pass directory and tell android to upload all images from the directory by magic.
Jun 9 '14 #2
rules engine
15 New Member
Just zip the content of the directory and upload it as single file.
Jun 10 '14 #3
avdeshyadav
1 New Member
When I started learning android development at one point, I needed to upload multiple images to a server that time, I faced this same problem. What helps me is I followed this question on stake overflow. I hope this
will help you.
https://stackoverflow.com/questions/8940969/uploading-multiple-image-on-php-server-from-android

for more advance level android development tutorials and sample code you can
https://itinsidenews.com/android-app...pment-tutorial
Apr 7 '21 #4
madankarmukta
308 Contributor
Zipping wont work.

Could you please tell me why and where is your get request.
May 8 '21 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3591
by: gramya | last post by:
hello, i got a code in google search which can upload images using php and javascript (iframes).I am trying to modify the code so that only one image which is browsed currently should be displayed....
1
2724
by: =?Utf-8?B?UmFqYWdvcGFs?= | last post by:
Question How to Upload multiple images in asp.net? (ex.Like a gmail file field)
2
3241
by: sarayu | last post by:
Hi All, How can i select multiple images by using shift or control key from my hard disk and upload it by using a submit button.For this what we use for selecting different images and...
3
2785
KeredDrahcir
by: KeredDrahcir | last post by:
I want to be able the upload multiple images at once. I can do a normal upload where the user browses for each image individually and I can also do where you have several browse images on the screen....
2
2724
by: ITProgrammer985 | last post by:
Hi all i posted a problem few days ago i am saving my images in a folder in the same project and only the path in data base i do not know if that the best solution but i considered the...
1
6732
by: ramrajram | last post by:
please help me ,am using below code.It is only one image display at a time also does not display an data values.how to display multiple images and data values. <% byte imgData = null ; ...
3
4888
by: rajmca | last post by:
I STORED MULTIPLE IMAGES IN MY SQL SERVER 2005. NOW I WANT TO RETRIEVE PARTICULAR CATEGORY OF IMAGES INTO MULTIPLE PICTUREBOX AT RUNTIME IN C# WINDOWS APPLICATION. i used the following code in my...
1
1332
by: jagadishk | last post by:
hi this is my code for uploading images into data base which is woring fine, but i want to upload multiple images an any one help me. <?php include 'config.php'; error_reporting(E_ALL ^...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.