繁体   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