1

I have a problem sending an image base64 encoded string. I have always the same error "Unsupported marker type 0xb7" in the server and the response is always "java.io.FileNotFoundException"

/** * This method convert a image in a string base64 encoded * * @return String Base64 */ public final static String getImageBase64(String fileName){ String encodedImage = null; Bitmap bm = BitmapFactory.decodeFile(Constants.ROUTE_IMAGES + fileName); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (bm != null){//Encuentra la imagen bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); try{ encodedImage = Base64.encodeToString(b, Base64.DEFAULT); }catch(Exception ex){ Log.d(TAG, "Error codificacion en Base64"); } }else{//NO encuentra la imagen Log.d(TAG, "bm is NULL"); } 

The next method is to send the data to a server

/** * Method to send information + image encoded base64 to a server and receive a response * * @param params String with information + image encoded base64 * @param urlToConnect URL server * @throws Exception */ public final static String sendData(String params, String urlToConnect) throws Exception{ URL url = null; HttpURLConnection conn = null; try{ url = new URL(urlToConnect); conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Content-Length", "" + Integer.toString(params.getBytes().length)); conn.setRequestProperty("Content-Language", "en-US"); conn.setUseCaches (false); conn.setDoInput(true); conn.setDoOutput(true); DataOutputStream wr = new DataOutputStream (conn.getOutputStream ()); wr.writeBytes (params); wr.flush (); wr.close (); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK){ Log.d(TAG, "Conexión OK"); }else{ Log.d(TAG, "Conexión FALLIDA"); } //Get Response -- Resultado InputStream is = conn.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is), 8*Constants.K); String line; StringBuffer response = new StringBuffer(); if (rd.readLine() == null){ Log.d(TAG, "Resultado NULL"); } while((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); Log.d(TAG, "Resultado: " + response.toString()); return response.toString(); }catch(IOException ex1){ Log.e(TAG, "Error en conexión ex1"); Log.d(TAG, ex1.toString()); throw new Exception("Error en conexión"); }catch(Exception ex2){ Log.e(TAG, "Error en conexión ex2"); throw new Exception("Error en conexión"); } } 

1 Answer 1

1

You do have to check first whether your Image is available or not in bitmap. Print your encoded string and just see it's coming or not.

If it is then let me know I'll paste my image uploading code to server.

Sign up to request clarification or add additional context in comments.

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.