Code Monkey home page Code Monkey logo

Comments (6)

codediodeio avatar codediodeio commented on July 25, 2024 4

It looks like this issue is caused when an image file is uploaded without an extension. The isResizedImage should be be expanded to check for the extension, or the function should auto-assign an extension if missing, or as @Salakar mentioned a custom metadata field may be the best option.

Here is a test case for the current implementation. In prod, the result is an infinite loop that uploads resized images with an empty filename. This will cause runaway billing if not caught early.

const path = require('path')

const suffixRegex = /_\d+x\d+$/;
const isResizedImageValidator = (fileName) => suffixRegex.test(fileName);

const filePath = 'thumbs/someImageWithoutExt_200x200' 
const fileName = path.basename(filePath);
const fileExtension = path.extname(filePath); // ""
const fileNameWithoutExtension = fileName.slice(0, -fileExtension.length);  // ""
const isResizedImage = isResizedImageValidator(fileNameWithoutExtension);

console.log(isResizedImage) // false :(

from extensions.

Salakar avatar Salakar commented on July 25, 2024 2

Hey @marvinsxtr, looks like this is the regex failing here to pickup that it's already a resized image.

I think we can look at removing this regex and instead use a custom metadata field to infer that an image has already been resized.

from extensions.

laurenzlong avatar laurenzlong commented on July 25, 2024 1

The fix is now live in v.0.1.1 of the extension. You can update via Firebase Console or CLI by running:
firebase ext:update storage-resize-images --project <projectId>

@codediodeio If you would like to opt out of resizing some images, my suggestion would be to put those images inside of a different bucket. The reason is that if they are in the same bucket as the one that the extension is listening to, a Cloud Function will still be triggered. This will lead to higher quota usage and potential cost.

from extensions.

laurenzlong avatar laurenzlong commented on July 25, 2024

Hi @codediodeio what do you mean by "image file is uploaded without an extension"? I want to make sure our fix that is in flight is going to solve this issue, and i'm having trouble reproducing the issue in the first place.

@marvinsxtr can you tell me exactly what your installation parameters are? What did you put for "Cloud Storage path for resized images", and what is the format and name of the image you then uploaded? Was it uploaded to the root of the bucket or a sub folder, if so, what was the name of the sub folder? As much detail as possible would be appreciated. Thanks!

from extensions.

michel-p avatar michel-p commented on July 25, 2024

@laurenzlong Hello LaurenWiong, just stumbled upon the exact same issue.
Extension parameters:
Deployment location : europe-west2
Cloud Storage bucket for imagesDescription : comando-78b26.appspot.com
Sizes of resized imagesDescription : 300x300,600x450
Cloud Storage path for resized images (Optional): thumbnails
Cache-Control header for resized images (Optional): Parameter not set

Name of images set without the MYME type at the end like follow ("profile-USERID") :

    const storageRef = storage().ref();
    let storedProfileImageUrl = "";
    let storedCoverImageUrl = "";

    if (profilePicture && !typeof coverPicture === "string") {
      const profileImageRef = storageRef.child(
        `profile-${userID}.${profilePicture.type}`
      );
      const storedProfileImage = yield profileImageRef.put(profilePicture);

      storedProfileImageUrl = yield storedProfileImage.ref.getDownloadURL();
    }```

from extensions.

codediodeio avatar codediodeio commented on July 25, 2024

I mean when you upload a file like ref('my-image').put(img), where the file mime type is an image, but the path is missing .png.

Setting a metadata property on the results, like use_resizer: false is the best solution IMO. It has the added benefit of allowing developers to opt-out of the extension for specific files.

from extensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.