jeudi 16 août 2018

Executing bucket.upload() function twice using if...else... conditional statement

I apologize if this is a newbie question to ask.

But I'm trying to execute bucket.upload() twice to upload two different files (see code below). Shouldn't the if...then... conditional statement work? If not, is there a better approach to try and execute bucket.upload() multiple times?

Thanks in advance.

if (bucket.upload(
        "/tmp/uploaded-image.jpg",
        {
          uploadType: "media",
          destination: "/places/" + uuid + ".jpg",
          metadata: {
              metadata: {
                  contentType: "image/jpeg",
                  firebaseStorageDownloadTokens: uuid
              }
          }
        },
        (err, file) => {
          if (!err) {
            return response.status(201).json({
              imageUrl:
                "https://firebasestorage.googleapis.com/v0/b/" +
                bucket.name +
                "/o/" +
                encodeURIComponent(file.name) +
                "?alt=media&token=" +
                uuid,
              imagePath: "/places/" + uuid + ".jpg"
            });
          } else {
            console.log(err);
            return response.status(500).json({ error: err });
          }
        })) {
        return bucket.upload(
        "/tmp/uploaded-coverImage.jpg",
        {
          uploadType: "media",
          destination: "/coverPlaces/" + uuid + ".jpg",
          metadata: {
              metadata: {
                  contentType: "image/jpeg",
                  firebaseStorageDownloadTokens: uuid
              }
          }
        },
        (err, file) => {
          if (!err) {
            return response.status(201).json({
              coverImageUrl:
                "https://firebasestorage.googleapis.com/v0/b/" +
                bucket.name +
                "/o/" +
                encodeURIComponent(file.name) +
                "?alt=media&token=" +
                uuid,
              coverImagePath: "/coverPlaces/" + uuid + ".jpg"
            });
          } else {
            console.log(err);
            return response.status(500).json({ error: err });
          }
        }
      );

Aucun commentaire:

Enregistrer un commentaire