0

is there any method for uploading images from android to php server without using any external library? if available just give me example.

2
  • If you are uploading small files like images, this could be relevant Android post Base64 String to PHP Commented Feb 17, 2014 at 6:23
  • @NikolaDespotoski i tried your solution but gives error due to String image_str = Base64.encodeBytes(byte_arr); unavailablity of encodeBytes() function where i will get this library Commented Feb 17, 2014 at 6:25

2 Answers 2

0

first convert your image into a base 64 byte array encoded string. after that send it to php. extract on server side.Then store that string in MySQL. after that send that string to android client. extract image string and decode with base 64 decode. after that you will get byte array you can simply show in your image view. for your reference I will show some code

     String imagedata = Base64.encodeToString(thumbnailArray,Base64.DEFAULT);
            mJobject.put("imagebyte",imagedata);
              mJArray.put(mJobject);

            JSONArray json=new JSONArray(response);
            JSONObject jo = null;

           imageArray=new String[json.length()];

         imageArray[i]=jo.getString("imageid");

          completeImage= Base64.decode(imageArray[0],Base64.DEFAULT); 
Bitmap bitmap = BitmapFactory.decodeByteArray(completeImage , 0, completeImage.length);
Sign up to request clarification or add additional context in comments.

2 Comments

can you give me complete solution link?
for solution you can find in this link Android post Base64 String to PHP
0

See here is complete code just try this one

Image save to Server

  AsyncTask<Void, Void, HttpEntity> editProfileTask = new AsyncTask<Void, Void, HttpEntity>() {

  @Override
    protected HttpEntity doInBackground(Void... params) {          
     HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("Your url"); // your url

  try {                     
    MultipartEntity reqEntity = new MultipartEntity();
    reqEntity.addPart("firstname",new StringBody(firstnameEV.getText().toString(),
    "text/plain",Charset.forName("UTF-8")));
               "text/plain",Charset.forName("UTF-8")));
   if (file != null) {
       reqEntity.addPart("image",new FileBody(((File) file),"application/zip"));
      }         
      httppost.setEntity(reqEntity);
       HttpResponse resp = httpclient.execute(httppost);          
     HttpEntity resEntity = resp.getEntity();
     return resEntity;
    } catch (ClientProtocolException e) {
      e.printStackTrace();
     } catch (IOException e) {
     e.printStackTrace();
     }return null;
     }
    @Override
  protected void onPostExecute(HttpEntity resEntity) {
 if (resEntity != null) {             
   try {
     JSONObject responseJsonObject = new JSONObject(EntityUtils.toString(resEntity));
      String status = responseJsonObject.getString("status");             
       if (status.equals("success")) {
            Toast.makeText(activity, "Your Profile is updated", Toast.LENGTH_LONG).show();
             String data = responseJsonObject.getString("data");              
             isUpdatedSuccessfully=true;            
       } else {
          Toast.makeText(activity, "Profile not updated", Toast.LENGTH_LONG).show();
     }
    } catch (Exception e) {
   e.printStackTrace();
  }
    }            
  }
   };
  editProfileTask.execute(null, null, null);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.