2
I need to send this image to my post api,
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 livview.setImageBitmap(thumbnail); the obtained image, to my database ..
Related https://answall.com/questions/205998/upload-jpeg-via-json
– Ismael
But it was not answered ;/
– Thiago Camargo
I’ve marked it as related that you can make it easier to find the answer if it’s answered first. Right here will appear as "Linked".
– Ismael
Can I suggest any client? Or would you like to use one in particular?
– Leonel Sanches da Silva
Thank you Ismael !
– Thiago Camargo
Gypsy I’m using the Dreamfactory
– Thiago Camargo