3

I need to take a picture from my camera app and upload the photo to my firebase storage. In the same time I also need to upload the thumbnail version of same image file. I need to fetch the url of the image and store it to database. I am new to firebase and working for a college project. I need thumbnail so that when loading the image, first i need to load the thumbnail and as per condition i will load the full size image

Future getImage() async{
var tempImage = await ImagePicker.pickImage(source: ImageSource.camera,imageQuality: 30);


setState(() {

  sampleImage=tempImage;
  Im.Image image = decodeImage(sampleImage.readAsBytesSync());
  Im.Image thumbnail = copyResize(image, width: 120,height: 120);
  imageThumb=thumbnail as File;

});
}


bool validateAndSave(){
final form = formKey.currentState;
if(form.validate()){
  form.save();
  return true;
}else{return false;}
}


void uploadStatusImage() async{
  goToHomePage();
  if(validateAndSave()){
    final StorageReference postImageRef= FirebaseStorage.instance.ref().child("Post Images");

    var timeKey=new DateTime.now();
    final StorageUploadTask uploadTask=postImageRef.child(timeKey.toString()+".jpg").putFile(sampleImage);

    final StorageUploadTask uploadTaskThumb=postImageRef.child(timeKey.toString()+"thumb.jpg").putFile(imageThumb);




    var ImageUrl = await(await uploadTask.onComplete).ref.getDownloadURL();
    var ImageThumbUrl = await(await uploadTaskThumb.onComplete).ref.getDownloadURL();

    this.url=ImageUrl.toString();
    this.url1=ImageThumbUrl.toString();
    print("Image Url= "+url);



    saveTodatabase(url,url1);

  }
}

void saveTodatabase(url,url1) async {
var dbTimekey=new DateTime.now();
var formatDate=new DateFormat('MM d, yyyy');
var formatTime=new DateFormat('EEEE, hh:mm aaa');

String date=formatDate.format(dbTimekey);
String time=formatTime.format(dbTimekey);



var data = {
  "image":url,
  "imagethumb":url1,
  "description": _myValue,
  "date": date,
  "time": time,

};

await databaseReference.collection("posts")
    .document(dbTimekey.toString())
    .setData(data);

//ref.child("Posts").push().set(data);
}
5
  • Did you find any solutions to this? Commented Nov 8, 2019 at 17:08
  • Not yet but actively searching for solution Commented Nov 10, 2019 at 2:51
  • hey pal, any update on this? Commented Jul 8, 2020 at 10:19
  • Any update on this? What about the Firebase resize image package? Or saving and uploading two sizes with image picker, sounds expensive though? Commented Aug 15, 2020 at 21:01
  • also looking for an update in 2022 Commented Jul 21, 2022 at 14:26

1 Answer 1

0

A workaround here is to use thumbnailer plugin which could help display the image as a thumbnail instantly.

Firesbase also has an extension that could resize images to generate thumbnails. This gives an option to keep or delete the original image.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.