android - How to send bitmap via http post to server -


i have picture camera bitmap. picture want send jpeg server via http post, this:

bitmap photo; stringentity reqentity = new stringentity(photo); httpclient httpclient = new defaulthttpclient(); httpresponse response = httpclient.execute(request); 

i have code azure

//request headers.  request.setheader("content-type", "application/json"); request.setheader("ocp-apim-subscription-key", subscriptionkey);  // request body.  stringentity reqentity = new stringentity("{\"url\":\"upload.wikimedia.org/wikipedia/comm‌​ons/c/c3/…\"}");  request.setentity(reqentity); 

convert bitmap base64 string, try below code , post string server

public static string encodetobase64(bitmap image) {    bitmap immagex=image;    bytearrayoutputstream baos = new bytearrayoutputstream();    immagex.compress(bitmap.compressformat.png, 100, baos);    byte[] b = baos.tobytearray();    string imageencoded = base64.encodetostring(b,base64.default);    return imageencoded; }  public static bitmap decodebase64(string input) {    byte[] decodedbyte = base64.decode(input, 0);    return bitmapfactory.decodebytearray(decodedbyte, 0, decodedbyte.length); } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -