簡體   English   中英

從 firebase 存儲和實時數據庫中獲取圖像

[英]Get images from firebase storage and realtime database

所以,我想讓用戶同時上傳多張圖片到 firebase 存儲。 我已經成功地完成了那部分,但現在我想找回圖像。 起初,我為每個用戶上傳一張圖像並將圖像 ID 保存到實時數據庫中,因此很容易通過圖像 ID 檢索圖像。 但是現在我怎樣才能將多個圖像保存到每個用戶的實時數據庫中,我不能使用相同的子名稱,因為它將被舊的替換。 有任何想法嗎??

上傳圖像並在實時數據庫上設置 id:

private void Fileuploader() throws FileNotFoundException {
        String imageid;

        progress.showProgress(profuctadd.this,"Loading...",false);
        DatabaseHelper databaseHelper = new DatabaseHelper(profuctadd.this);
        Cursor getimage = databaseHelper.GetPath();
        int count = 0;
        while (getimage.moveToNext()){
            Bitmap bm = BitmapFactory.decodeFile(getimage.getString(0));
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            bm.compress(Bitmap.CompressFormat.JPEG, 35, out);
            imageid = arabic.getText().toString()+"-"+System.currentTimeMillis()+"_"+(count++)+"."+getExtension(uri);
            System.out.println("IMAGES UPLOADEDDDD: "+ imageid);
            String id = getIntent().getStringExtra("storeid");
            member.setImageid(imageid);
            reference.child(id).child(arname).setValue(member);
            byte[] data = out.toByteArray();
            StorageReference Ref = mStorageRef.child(imageid);
            Ref.putBytes(data)
                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                            // Get a URL to the uploaded content
                            //Uri downloadUrl = taskSnapshot.getDownloadUrl();
                            //Toast.makeText(profuctadd.this,"Image uploaded",Toast.LENGTH_LONG).show();
                            progress.hideProgress();
                            Intent intent = new Intent(profuctadd.this,showProducts.class);
                            intent.putExtra("spec",getIntent().getStringExtra("spec"));
                            intent.putExtra("storeid",getIntent().getStringExtra("storeid"));
                            startActivity(intent);
                            DatabaseHelper mDatabaseHelper = new DatabaseHelper(profuctadd.this);
                            Cursor cursor2 = mDatabaseHelper.DeleteDataOfTableImagesAr();
                            cursor2.moveToNext();
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception exception) {
                            // Handle unsuccessful uploads
                            // ...
                            Toast.makeText(profuctadd.this,"Failed",Toast.LENGTH_LONG).show();
                        }
                    });

        }





    }

我的 firebase 數據庫:

Firebase 數據庫

您可以像這樣在圖像節點中保存多個特定用戶的圖像。

DatabaseReference dr =  FirebaseDatabase.getInstance().getReference("tL131);

 dr.child("images").push().setValue(String.ValueOf(taskSnapshot.getDownloadUrl()));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM