Skip to content

Commit a2bf4a9

Browse files
author
Ashley Gau
authored
Merge pull request #183 from firebase/@invertase/resize-content-type
fix(storage-resize-images): ensure content type is always available
2 parents bd4baad + 5367830 commit a2bf4a9

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

storage-resize-images/POSTINSTALL.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ The extension also copies the following metadata, if present, from the original
2929
- [`Content-Type`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Type)
3030
- [user-provided metadata](https://cloud.google.com/storage/docs/metadata#custom-metadata) (except Firebase storage download tokens)
3131

32-
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/).
32+
Be aware of the following when using this extension:
33+
34+
- 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`).
35+
36+
- 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/).
3337

3438
### Monitoring
3539

storage-resize-images/functions/lib/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ logs.init();
4444
exports.generateResizedImage = functions.storage.object().onFinalize((object) => __awaiter(this, void 0, void 0, function* () {
4545
logs.start();
4646
const { contentType } = object; // This is the image MIME type
47+
if (!contentType) {
48+
logs.noContentType();
49+
return;
50+
}
4751
const isImage = validators.isImage(contentType);
4852
if (!isImage) {
4953
logs.contentTypeInvalid(contentType);

storage-resize-images/functions/lib/logs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const config_1 = require("./config");
1919
exports.complete = () => {
2020
console.log("Completed execution of extension");
2121
};
22+
exports.noContentType = () => {
23+
console.log(`File has no Content-Type, no processing is required`);
24+
};
2225
exports.contentTypeInvalid = (contentType) => {
2326
console.log(`File of type '${contentType}' is not an image, no processing is required`);
2427
};

storage-resize-images/functions/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export const generateResizedImage = functions.storage.object().onFinalize(
4848
logs.start();
4949
const { contentType } = object; // This is the image MIME type
5050

51+
if (!contentType) {
52+
logs.noContentType();
53+
return;
54+
}
55+
5156
const isImage = validators.isImage(contentType);
5257
if (!isImage) {
5358
logs.contentTypeInvalid(contentType);

storage-resize-images/functions/src/logs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export const complete = () => {
2020
console.log("Completed execution of extension");
2121
};
2222

23+
export const noContentType = () => {
24+
console.log(`File has no Content-Type, no processing is required`);
25+
};
26+
2327
export const contentTypeInvalid = (contentType: string) => {
2428
console.log(
2529
`File of type '${contentType}' is not an image, no processing is required`

0 commit comments

Comments
 (0)