2017-04-16 39 views
3

如何與Android的凌空MVC的API後method.I上傳圖片曾經嘗試這樣做:如何與Android的凌空MVC的API POST方法上傳圖像

StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL, 
      new Response.Listener<String>() { 
       @Override 
       public void onResponse(String responec) { 
        loading.dismiss(); 
        Log.e("tag","data :"+responec); 
       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError volleyError) { 
        loading.dismiss(); 
        Log.e("tag","data :"+volleyError.toString()); 
       } 
      }){ 
     @Override 
     protected Map<String, String> getParams() throws AuthFailureError { 
      String image = getStringImage(bitmap); 
      Map<String,String> params = new Hashtable<String, String>(); 
      params.put(KEY_IMAGE, image); 
      return params; 
     } 
    }; 
    RequestQueue requestQueue = Volley.newRequestQueue(this); 
    requestQueue.add(stringRequest); 

我該怎麼處理這個問題。

回答

-1

我,我永遠是位編碼使用

public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality) 
{ 
    ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream(); 
    image.compress(compressFormat, quality, byteArrayOS); 
    return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT); 
} 

然後發送的base64到您的API一個base64 ,,

在反向模式解碼Base64和顯示用圖像

public static Bitmap decodeBase64(String input) 
{ 
    byte[] decodedBytes = Base64.decode(input, 0); 
    return BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length); 
} 

ImageViewObject.setImageBitmap();