diff --git a/storage-resize-images/POSTINSTALL.md b/storage-resize-images/POSTINSTALL.md index 5f942678b..15392bd11 100644 --- a/storage-resize-images/POSTINSTALL.md +++ b/storage-resize-images/POSTINSTALL.md @@ -29,7 +29,11 @@ The extension also copies the following metadata, if present, from the original - [`Content-Type`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Type) - [user-provided metadata](https://cloud.google.com/storage/docs/metadata#custom-metadata) (except Firebase storage download tokens) -Note that if you configured the `Cache-Control header for resized images` param, the specified value will overwrite the value copied from the original image. Learn more about image metadata in the [Cloud Storage documentation](https://firebase.google.com/docs/storage/). +Be aware of the following when using this extension: + +- Each original image must have a valid [image MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#Image_types) specified in its [`Content-Type` metadata](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Type) (for example, `image/png`). + +- If you configured the `Cache-Control header for resized images` parameter, your specified value will overwrite the value copied from the original image. Learn more about image metadata in the [Cloud Storage documentation](https://firebase.google.com/docs/storage/). ### Monitoring diff --git a/storage-resize-images/functions/lib/index.js b/storage-resize-images/functions/lib/index.js index d0afe9238..e1b5f0c18 100644 --- a/storage-resize-images/functions/lib/index.js +++ b/storage-resize-images/functions/lib/index.js @@ -44,6 +44,10 @@ logs.init(); exports.generateResizedImage = functions.storage.object().onFinalize((object) => __awaiter(this, void 0, void 0, function* () { logs.start(); const { contentType } = object; // This is the image MIME type + if (!contentType) { + logs.noContentType(); + return; + } const isImage = validators.isImage(contentType); if (!isImage) { logs.contentTypeInvalid(contentType); diff --git a/storage-resize-images/functions/lib/logs.js b/storage-resize-images/functions/lib/logs.js index 19d0f3586..ee75217aa 100644 --- a/storage-resize-images/functions/lib/logs.js +++ b/storage-resize-images/functions/lib/logs.js @@ -19,6 +19,9 @@ const config_1 = require("./config"); exports.complete = () => { console.log("Completed execution of extension"); }; +exports.noContentType = () => { + console.log(`File has no Content-Type, no processing is required`); +}; exports.contentTypeInvalid = (contentType) => { console.log(`File of type '${contentType}' is not an image, no processing is required`); }; diff --git a/storage-resize-images/functions/src/index.ts b/storage-resize-images/functions/src/index.ts index d7bdcbe48..43d943410 100644 --- a/storage-resize-images/functions/src/index.ts +++ b/storage-resize-images/functions/src/index.ts @@ -48,6 +48,11 @@ export const generateResizedImage = functions.storage.object().onFinalize( logs.start(); const { contentType } = object; // This is the image MIME type + if (!contentType) { + logs.noContentType(); + return; + } + const isImage = validators.isImage(contentType); if (!isImage) { logs.contentTypeInvalid(contentType); diff --git a/storage-resize-images/functions/src/logs.ts b/storage-resize-images/functions/src/logs.ts index 925286427..076c34d4f 100644 --- a/storage-resize-images/functions/src/logs.ts +++ b/storage-resize-images/functions/src/logs.ts @@ -20,6 +20,10 @@ export const complete = () => { console.log("Completed execution of extension"); }; +export const noContentType = () => { + console.log(`File has no Content-Type, no processing is required`); +}; + export const contentTypeInvalid = (contentType: string) => { console.log( `File of type '${contentType}' is not an image, no processing is required`