Home How to upload Multiple Images to firebase and get the URL in separate childs just am getting all the URL in one child value
Reply: 1

How to upload Multiple Images to firebase and get the URL in separate childs just am getting all the URL in one child value

Hamu Damu
Hamu Damu Published in 2017-11-14 23:30:40Z
public class MainActivity extends AppCompatActivity {

    String key;
    private ImageView mImageView;
    private FirebaseStorage mStorageRef;
    private Button mButton;
    private StorageTask mUploadTask;
    private List<Uri> uploadedImages = new ArrayList<>();

    private DatabaseReference mRefre;
    ArrayList<String> filepath = new ArrayList<>();

    protected void onCreate(Bundle savedInstanceState) {

        mImageView = (ImageView) findViewById(R.id.hhhh);

        mRefre = FirebaseDatabase.getInstance().getReference();
        mButton = (Button) findViewById(R.id.addphoto);

        mButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {



    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {

            case FilePickerConst.REQUEST_CODE:

                if (resultCode == RESULT_OK && data != null) {

                    final ArrayList<String> filepath;
                    filepath = data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_PHOTOS);


                    for (String path : filepath) {

                        final Uri file = Uri.fromFile(new File(path));
                        key = mRefre.child("products").push().getKey();

                        StorageReference photoRef = FirebaseStorage.getInstance().getReference("Images").child(uploadedImages + file.getLastPathSegment());

                        mUploadTask = photoRef.putFile(file);
                        mUploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                                Uri downloadUrl = taskSnapshot.getDownloadUrl();

                                HashMap userMap = new HashMap();

I am doing firebase project and trying to upload multiple images using imagepicker with a maximum of 3 images. The images are successfully uploaded to firebase storage but when I try to get the URL it saves the 3 images in one child Value. I am trying to save it in separate values and name them so I can retrieve them later.

How can I fix this?

Mike McDonald
Mike McDonald Reply to 2017-11-21 15:41:21Z

I'd try a different approach: instead of looping, use the built in Promise/Task construct. This is detailed: https://gist.github.com/mcdonamp/d4f1327b58ad69334ef06327184df790 or How to upload multiple files to Firebase? and Android Firebase multiple image upload

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298589 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO