我设法创建了一个选择图片并上传到Firebase存储的应用,但我需要的是选择/捕获(暂时不重要)并将其上传到我的compture存储。如果我能给出一个名字,那也将是完美的。
我的上传代码和附加android studio项目。
DropBox:https://www.dropbox.com/s/uqt3dpz7gw4ucvv/Nuotraukos.rar?dl=0
TABLE LIST IS: NEW_ENTRY|SAMPLE|NEW_ENTRY|SAMPLE
答案 0 :(得分:0)
我已经做到了,并且现在正在工作。
private void UploadImage (){
StringRequest stringRequest = new StringRequest(Request.Method.POST, UploadUrl,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String Response = jsonObject.getString("response");
Toast.makeText(MainActivity.this,Response,Toast.LENGTH_LONG).show();
mImageView.setImageResource(0);
mImageView.setVisibility(View.GONE);
mEditText.setText("");
mEditText.setVisibility(View.GONE);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
params.put("name",mEditText.getText().toString().trim());
params.put("image",ImageToString(bitmap));
return params;
}
};
SingletonClass.getInstance(MainActivity.this).addToRequestQue(stringRequest);
}
private String ImageToString(Bitmap bitmap){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte [] imgBytes = byteArrayOutputStream.toByteArray();
return Base64.encodeToString(imgBytes, Base64.DEFAULT);
}