我开发了一个应用程序,用户可以拍摄两张照片,然后将它们并排显示在Linearlayout(水平方向)中。一旦显示图片。我有一个用户按下上传按钮,将图片上传到firebase。我遇到的问题是只有一张图片正在上传而另一张则没有。如何将两张图片上传到同一文件路径,但为它们指定不同的名称:这是我当前可怕尝试的代码。
_uploadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
image_one.setDrawingCacheEnabled(true);
image_one.buildDrawingCache();
Bitmap bitmapOne = image_one.getDrawingCache();
ByteArrayOutputStream imageoneBytes = new ByteArrayOutputStream();
bitmapOne.compress(Bitmap.CompressFormat.JPEG, 100, imageoneBytes);
byte[] dataOne = imageoneBytes.toByteArray();
StorageReference filepathOne = mStorage.child(user_data.getString("uidkey", null)).child("Photos").child(_imageoneText.getText().toString());
filepathOne.putBytes(dataOne).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getBaseContext(), "Upload One Done", Toast.LENGTH_LONG).show();
Uri downloadUrl = taskSnapshot.getDownloadUrl();
Picasso.with(IdentificationActivity.this).load(downloadUrl).fit().centerCrop().into(image_one);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getBaseContext(), "Upload one failed", Toast.LENGTH_LONG).show();
}
});
image_two.setDrawingCacheEnabled(true);
image_two.buildDrawingCache();
Bitmap bitmapTwo = image_two.getDrawingCache();
ByteArrayOutputStream imagetwoBytes = new ByteArrayOutputStream();
bitmapTwo.compress(Bitmap.CompressFormat.JPEG, 100, imageoneBytes);
byte[] dataTwo = imagetwoBytes.toByteArray();
StorageReference filepathTwo = mStorage.child(user_data.getString("uidkey", null)).child("Photos").child(_imagetwotext.getText().toString());
filepathTwo.putBytes(dataTwo).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getBaseContext(), "Upload two Done", Toast.LENGTH_LONG).show();
Uri downloadUrl = taskSnapshot.getDownloadUrl();
Picasso.with(IdentificationActivity.this).load(downloadUrl).fit().centerCrop().into(image_two);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getBaseContext(), "Upload two failed", Toast.LENGTH_LONG).show();
}
});
}
});