Send JPG via JSON

2

I need to send this image to my api via post, but I do not know how to do that, thanks

private void onCaptureImageResult(Intent data) {
    Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);


    File destination = new File(Environment.getExternalStorageDirectory(),
            System.currentTimeMillis() + ".jpg");

    FileOutputStream fo;
    try {
        destination.createNewFile();
        fo = new FileOutputStream(destination);
        fo.write(bytes.toByteArray());
        fo.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    livview.setImageBitmap(thumbnail);
}

My post code:

         //  postDataParams.put("id_aut", mAutorliv);
            postDataParams.put("txnome_liv", mNomeliv);
            postDataParams.put("id_cat", mCatliv);
            postDataParams.put("id_subcat", mSubcatliv);
            postDataParams.put("ISBN", mIsbn);
            postDataParams.put("qt_pag", mNumeropaginas);
            postDataParams.put("edicao", mEdiçãoliv);
            postDataParams.put("ano", mLançamentoliv);
         //   postDataParams.put("id_idi", mIdiomaliv);
            postDataParams.put("desc_liv", mInfliv);
            postDataParams.put("vl_anuncio", mPreçoliv);
            postDataParams.put("img_livro", encodedImage);
            Log.e("resource", postDataParams.toString());


            JSONObject resource = new JSONObject();
            JSONArray array = new JSONArray();
            array.put(postDataParams);
            resource.put("resource", array);

            System.out.println(resource.toString());


            conn.connect();

            OutputStream os = conn.getOutputStream();
            BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(os, "UTF-8"));
            //writer.write(getPostDataString(postDataParams));
            writer.write(resource.toString());

            writer.flush();
            writer.close();
            os.close();


            int responseCode = conn.getResponseCode();

            if (responseCode == HttpsURLConnection.HTTP_OK) {
                Intent intent = new Intent(Activity_addinf.this, 
       MainActivity2.class);
                startActivity(intent);

                BufferedReader in = new BufferedReader(new 
    InputStreamReader(conn.getInputStream()));
                StringBuffer sb = new StringBuffer("");
                String line = "";

                while ((line = in.readLine()) != null) {

                    sb.append(line);
                    break;
                }

                in.close();
                return sb.toString();
            } else {
                return new String("false : " + responseCode);
            }
        } catch (Exception e) {
            return new String("Exception: " + e.getMessage());
        }
    }

I would like to send this to livview.setImageBitmap (thumbnail); the image obtained, to my bank ..

    
asked by anonymous 19.05.2017 / 21:01

0 answers