android
Uri filePath = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), resultUri);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
selectedPicture = Base64.encodeToString(imageBytes, Base64.DEFAULT);
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
implementation 'com.android.volley:volley:1.1.1'
private void updatePhoto() {
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
String flag = "";
String message = "";
try {
JSONObject root = new JSONObject(response);
JSONObject fff = new JSONObject(root.getString("flag"));
flag = fff.getString("flag");
message = fff.getString("message");
} catch (JSONException e) {
Log.d("myLog", "Parse Error");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
Log.d("myLog", "VolleyError Error " + error.toString());
}
}) {
@Override
protected Map<String, String> getParams() {
Log.d("myLog", "VolleyError filename 11 " + filename);
Map<String, String> params = new HashMap<>();
params.put("contents", contents.getText().toString());
params.put("mem_id", pref.getValue(RbPreference.MEM_ID, ""));
params.put("board_idx", board_idx);
params.put("mode", "write");
params.put("reg_id", reg_id);
params.put("pid", pid);
params.put("picture", selectedPicture);
params.put("filename", filename);
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
// To prevent timeout error
stringRequest.setRetryPolicy(new DefaultRetryPolicy(50000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
// Add the request to the RequestQueue.
stringRequest.setShouldCache(false);
queue.add(stringRequest);
}
php
if($filename){
$picture = $_POST["picture"];
$file_path = SAVE_FILE_DIR.'/board/'. $filename;
file_put_contents($file_path, base64_decode($picture));
}else{
$filename='';
}
'안드로이드' 카테고리의 다른 글
자바 특정일에 다음날 이전날 (0) | 2023.09.19 |
---|---|
Glide 큰 사이즈 이미지 로딩 (0) | 2023.09.19 |
php 다른 테이블의 리스트를 가져오기 (0) | 2022.11.11 |
앱 배포시 카카오 로그인 해시키 문제 (0) | 2022.03.30 |
ViewModel , Retrofit 이용한 대학교 검색 (0) | 2021.12.23 |