2

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);
});

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, Yesssss. Thanks for letting me know. I eventually found this document website but forgot to update the status. Thanks again.
0

Google Cloud Functions quotas:

Max uncompressed HTTP response size = 10MB per invocation

Max uncompressed HTTP request size = 10MB per invocation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.