1
votes

I'm resizing a file with cloud functions and uploading the file to Firebase functions. I want to set the content-type to. image/jpeg. I'm using google cloud storage to return a bucket..

const bucket = gcs.bucket(object.bucket);

and when I upload the file..

bucket.upload(imgPath, {
                destination: join(bucketDir, newImgName),
                metadata: {
                    metadata: {
                        contentType: 'image/jpeg',
                        firebaseStorageDownloadTokens: uuid
                    }
                }

            });

I able to access the file type of the image uploaded to Firebase Storage, which is application/octet-stream, which triggers the operation. This is also the content-type of the resized file. How can I set the content-type to 'image/jpeg?

1

1 Answers

3
votes

Your UploadOptions object passed as the second parameter is too deeply nested. You only use the inner metadata property for custom metadata. You can set contentType at the top level, according to the linked documentation.

bucket.upload(imgPath, {
    destination: join(bucketDir, newImgName),
    metadata: {
        contentType: 'image/jpeg',
    }
});

I don't know what firebaseStorageDownloadTokens is, so I left it off. It doesn't seem to be mentioned in the documentation. If you're trying to set that as custom metadata, then do use the nested metadata property.