简体   繁体   中英

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

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

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

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

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) {

                }
            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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