Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading multiple images to server
    primarykey
    data
    text
    <p>User can take 5-6 pictures in android side through camera. So, I used ACTION_IMAGE_CAPTURE. In the onActivityResult I do this to collect the bitmap of the image taken by the camera. Suppose for first taken pic and second taken pic as below.</p> <pre><code>if(requestCode == 1) { bitMap1 = (Bitmap)extras.get("data"); imageView1.setImageBitmap(bitMap1); globalvar = 2; } if(requestCode == 2) { bitMap1 = (Bitmap)extras.get("data"); imageView2.setImageBitmap(bitMap2); globalvar = 2; } </code></pre> <p><strong>To send these images to the php server, I do the following..</strong></p> <pre><code>protected String doInBackground(Integer... args) { // Building Parameters ByteArrayOutputStream bao1 = new ByteArrayOutputStream(); bitMap1.compress(Bitmap.CompressFormat.JPEG, 90, bao1); byte [] bytearray1 = bao1.toByteArray(); String stringba1 = Base64.encode(bytearray1); ByteArrayOutputStream bao2 = new ByteArrayOutputStream(); bitMap2.compress(Bitmap.CompressFormat.JPEG, 90, bao2); byte [] bytearray2 = bao2.toByteArray(); String stringba2 = Base64.encode(bytearray2); String parameter1 = "tenant"; String parameter2 = "price"; List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("person",parameter1)); params.add(new BasicNameValuePair("price",parameter2)); params.add(new BasicNameValuePair("image1",stringba1)); params.add(new BasicNameValuePair("image2",stringba2)); JSONObject json = jParser.makeHttpRequest(requiredurl, "POST", params); Log.d("Details", json.toString()); int success = json.getInt("connected"); if (success == 1) { //blah blah } } </code></pre> <p>Here is the <strong>makeHttpRequest() method</strong>:</p> <pre><code>public JSONObject makeHttpRequest(String url, String method, List&lt;NameValuePair&gt; params) { // Making HTTP request try { // check for request method if(method == "POST"){ // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } ................ ....................... // Here the result is extracted and made it to json object ............................. // return JSON return jObj; // returning the json object to the method that calls. } </code></pre> <p><strong>Below is the php code snippet:</strong></p> <pre><code>$name = $_POST[person]; $price = $_POST[price]; $binary1 = base64_decode($image2); $binary2 = base64_decode($image2); $file1 = tempnam($uploadPath, 'image2'); $fp1 = fopen($file1, 'wb'); fwrite($fp1, $binary1); fclose($fp1); ................. ............................ </code></pre> <p>However I am unable to store images in sever side folder. Even I have seen in some links saying that Base64 is not preferable way while uploading multiple images. Can someone please suggest me how to proceed? Have seen <a href="https://stackoverflow.com/questions/8940969/uploading-multiple-image-on-php-server-from-android">this</a> and many other links, but can't get how to proceed in my requirement as I have to even send some data(like person name, price) along with that images. Any help on this is greatly appreciated.</p> <p><strong>NOTE:</strong> Even if someone can suggest me how to save that above temp file($file1) in the server folder, I would be very thankful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload