1

The script file is rendered from server side, and when I using the code as below to download data from the script

const blob = new Blob([data]);
var a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "1.mp4";
a.click();
URL.revokeObjectURL(a.href);

it shows that document is not defined. Is there any way to solve this problem?

1 Answer 1

1

I solved the problem through split the code into two parts.

  1. While server side rendering, I print the blob's url in console:
const blob = new Blob([data]);
console.log(URL.createObjectURL(blob));
  1. And While client side rendering, I download the blob manually:
var a = document.createElement("a");
a.href = 'blob:{paste the url address}';
a.download = "1.mp4";
a.click();
URL.revokeObjectURL(a.href);
Sign up to request clarification or add additional context in comments.

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.