472,805 Members | 942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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

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 18269
There is no way, you can pass directory and tell android to upload all images from the directory by magic.
Jun 9 '14 #2
Just zip the content of the directory and upload it as single file.
Jun 10 '14 #3
avdeshyadav
1 Bit
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 256MB
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
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
by: =?Utf-8?B?UmFqYWdvcGFs?= | last post by:
Question How to Upload multiple images in asp.net? (ex.Like a gmail file field)
2
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
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
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
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
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
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
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.