Zac
Zac

Reputation: 2081

File Object Not Defined NuxtJS AsyncData()

I am using NuxtJS's AsyncData method to fetch a video file from an API and then return to the page as a file object.

Like so:

async AsyncData({$axios}){
    var user_video = null;
    try{
        var video = $axios.get("my awesome url");
        user_video = new File([video], "video.mp4",{type:"video/mp4"}); // <= this line
    }catch(error){
        console.log(error);
        console.log("no saved video");
    }

    return {user_video};
}

In in the server side console, it shows this error:

ReferenceError: File is not defined
    at asyncData (pages/send/video.js:155:11)
    at process._tickCallback (internal/process/next_tick.js:68:7)
no saved video

I've looked at other nuxtjs Content keys to use that may have something to do with creating a new File Object, but i have not found any. https://nuxtjs.org/api/context

I've tried searching for a similar error with using the File object in asyncdata, though I have not found anything.

Any suggestions?

Edit ---- Also To Add:

the URL I am fetching from brings to a download dialogue box in case this may be related.

Upvotes: 0

Views: 1095

Answers (1)

Aldarund
Aldarund

Reputation: 17621

asyncData is executed on server on first load. And on server there no such thing as File in node. So you cant use File on your server code.

You should either dont use File or dont use asyncData and use mounted hook to fetch and set your data.

Upvotes: 2

Related Questions