با سلام
من یه پروژه ای دارم که توی اون باید عکس رو روی سرور اپلود کنم و برای این کار از کتابخونه volley استفاده میکنم ولی این کتابخونه برای عکسایی با حجم بیشتر از 1 مگابایت کار نمیکنه. به این صورت که خیلی زمان میبره و در اخر هم ارور تایم اوت میده . میخواستم بدونم کسی راه حلی داره که بشه عکس با حجم بالا رو هم اپلود کرد ؟؟ یا این که کلا یه کتابخونه جایگزین پیشنهاد کنه؟؟
کدمم اینه:
public class UploadImage {
private String uploadUrl = "/json_file/image_upload";
private String type = "";
String url = "";
public String uploadImage(final Context context, final String type, final Bitmap bitmap){
this.type = type;
final android.support.v7.app.AlertDialog dialog = new BuildProgressDialog(context).buildDialog().create( );
dialog.show();
StringRequest request = new StringRequest(Request.Method.POST,new DataBaseHelper(context).getUrl()+ uploadUrl,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
url = response;
Toast.makeText(context,response,Toast.LENGTH_SHORT ).show();
dialog.dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context,error.toString(),Toast.LENG TH_SHORT).show();
dialog.dismiss();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String,String> map = new HashMap<>();
map.put("image",imageToString(bitmap));
map.put("type",type);
return map;
}
};
request.setRetryPolicy(new DefaultRetryPolicy( 50000, 5, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
MySingleton.getInstance(context).addToRequestque(r equest);
return url;
}
public String imageToString(Bitmap bitmap){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
if (type.equals("jpeg")){
bitmap.compress(Bitmap.CompressFormat.JPEG,100,byt eArrayOutputStream);
} else if (type.equals("png")){
bitmap.compress(Bitmap.CompressFormat.PNG,100,byte ArrayOutputStream);
}
byte[] imgBytes = byteArrayOutputStream.toByteArray();
return Base64.encodeToString(imgBytes,Base64.DEFAULT);
}
}