简体   繁体   English

无法在firebase存储中获取图像

[英]Cant get image in firebase storage

I tried to use GLide and Picasso but it seems I cant figure out and find where is the problem我尝试使用GLide和毕加索,但似乎无法弄清楚问题出在哪里

Uploading an image from storage was successful and this is how I upload an image从存储上传图像成功,这就是我上传图像的方式

qrPictures = mStorageRef.child("QRCodes/"+text.getText().toString()+".jpg");

Bitmap bitmap = qr.getDrawingCache();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();

UploadTask uploadTask = qrPictures.putBytes(data);

String ID = database.push().getKey();
Random r = new Random();
database.child(ID).setValue(new QrCodeModel(String.valueOf(r.nextInt(18873+3+1)),text.getText().toString(),taskSnapshot.getUploadSessionUri().toString()));

Model模型

public class QrCodeModel {
public String id;
public String name;
public String qrcodetemplate;

public  QrCodeModel(){}
public QrCodeModel(String id, String name, String qrcodetemplate) {
    this.id = id;
    this.name = name;
    this.qrcodetemplate = qrcodetemplate;
}

public String getId() {        return id;    }

public void setId(String id) {        this.id = id;    }

public String getName() {        return name;    }

public void setName(String name) {        this.name = name;    }

public String getQrcodetemplate() {        return qrcodetemplate;    }

public void setQrcodetemplate(String qrcodetemplate) {        this.qrcodetemplate = qrcodetemplate;  }

Lastly this is how I get the image using the ID provided by the user最后,这就是我使用用户提供的ID获取图像的方式

database.orderByChild("id").equalTo(newname.getText().toString()).addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    for(DataSnapshot snapshot:dataSnapshot.getChildren()){
                        QrCodeModel details = snapshot.getValue(QrCodeModel.class);
                        /*Picasso.get()
                                .load(details.qrcodetemplate)
                                .resize(50, 50)
                                .centerCrop()
                                .into(qr);*/
                        Glide.with(MainActivity.this)
                                .load(details.qrcodetemplate)
                                .centerCrop()
                                .into(qr);
                        Toast.makeText(MainActivity.this,details.name,Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {

                }
            });

I tried to use GLide and Picasso but it seems I cant figure out and find where is the problem我尝试使用GLide和毕加索,但似乎无法弄清楚问题出在哪里

Uploading an image from storage was successful and this is how I upload an image从存储上传图像成功,这就是我上传图像的方式

qrPictures = mStorageRef.child("QRCodes/"+text.getText().toString()+".jpg");

Bitmap bitmap = qr.getDrawingCache();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();

UploadTask uploadTask = qrPictures.putBytes(data);

String ID = database.push().getKey();
Random r = new Random();
database.child(ID).setValue(new QrCodeModel(String.valueOf(r.nextInt(18873+3+1)),text.getText().toString(),taskSnapshot.getUploadSessionUri().toString()));

Model模型

public class QrCodeModel {
public String id;
public String name;
public String qrcodetemplate;

public  QrCodeModel(){}
public QrCodeModel(String id, String name, String qrcodetemplate) {
    this.id = id;
    this.name = name;
    this.qrcodetemplate = qrcodetemplate;
}

public String getId() {        return id;    }

public void setId(String id) {        this.id = id;    }

public String getName() {        return name;    }

public void setName(String name) {        this.name = name;    }

public String getQrcodetemplate() {        return qrcodetemplate;    }

public void setQrcodetemplate(String qrcodetemplate) {        this.qrcodetemplate = qrcodetemplate;  }

Lastly this is how I get the image using the ID provided by the user最后,这就是我使用用户提供的ID获取图像的方式

database.orderByChild("id").equalTo(newname.getText().toString()).addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    for(DataSnapshot snapshot:dataSnapshot.getChildren()){
                        QrCodeModel details = snapshot.getValue(QrCodeModel.class);
                        /*Picasso.get()
                                .load(details.qrcodetemplate)
                                .resize(50, 50)
                                .centerCrop()
                                .into(qr);*/
                        Glide.with(MainActivity.this)
                                .load(details.qrcodetemplate)
                                .centerCrop()
                                .into(qr);
                        Toast.makeText(MainActivity.this,details.name,Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {

                }
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM