Peter Fields
Peter Fields

Reputation: 389

Firebase cloud function logs 'Error: incorrect function response. Function invocation was interrupted.'

I have a website with 2 links. One to download an MP3 and one to download a WAV file

For example:

<a href="https://mywesbite.com/download?file=//assets.net/beethoven-fur-elise.wav" download="beethoven-fur-elise">Download WAV</a>

and

<a href="https://mywesbite.com/download?file=//assets.net/beethoven-fur-elise.mp3" download="beethoven-fur-elise">Download MP3</a>

I have written a cloud function for /download/ which will send the remote audio file so the user will be prompted to download the file and not have it open in a new tab and play.

The MP3 link works but the WAV file fails and the error logs show this

Error: incorrect function response. Function invocation was interrupted.
Function execution took 2941 ms, finished with status: 'response error'

Please note that on my local machine both WAV & MP3s work.

The MP3 files are around 3-6 MB

The WAV files are around 40 MB

Firebase Cloud function

const express = require('express');
const request = require('request');
const cors = require('cors');
const helmet = require('helmet');

const downloadApp = express();

downloadApp.use(helmet());
downloadApp.use(
  cors({
    origin: true
  })
);

downloadApp.get('/download', (req, res) => {
  res.set(
    'Cache-control',
    `public, max-age=${CONFIG.TIME.CACHE_IN_USERS_BROWSER}, s-maxage=${
      CONFIG.TIME.CACHE_IN_CDN
    }`
  );

  /**
   *
   * contentType = 'audio/wav'
   *          OR
   * contentType = 'audio/mpeg'
   *
   * */

  res.setHeader('Content-Type', contentType);
  res.setHeader('Content-disposition', `attachment; filename="${filename}"`);

  // External URL to MP3 or WAV
  const externalUrl = 'https://external-website.com/something.wav';

  request
    .get(externalUrl)
    .on('error', function(err) {
      console.error('Download Error: ', err);
    })
    .pipe(res);
});

Upvotes: 2

Views: 503

Answers (2)

Peter Fields
Peter Fields

Reputation: 389

Google Cloud Functions quotas:

Max uncompressed HTTP response size = 10MB per invocation

Max uncompressed HTTP request size = 10MB per invocation

Upvotes: 0

Danilo Mz
Danilo Mz

Reputation: 499

I was faced with a somewhat similar issue, and eventually figured the failure had to do with the quotas and limits described here.

All my cloud functions failed for responses > 10MB.

Upvotes: 2

Related Questions