Programmatically import video from url into a plugin

I’m trying to import a video file from an url inside a plugin using the ‹ api/v1/videos/upload › rest api.
Can you please help me with a simple example on how to do it?
I’ve tried different methods (axios, superagent, plain https, streams) but all are failing.

Thank you in advance
Best regards

Example that was working on peertube v4 (inside main.js server side plugin):
(stream is a stream retrieved from an url « streamingUrl » that point to a mp4 file with axios get responseType stream)

const res = await axios.get(encodeURI(streamingUrl), {
responseType: ‹ stream ›
});
const stream = res.data;
const size = parseInt(res.headers[‹ content-length ›], 10);

const formData = new FormData();
formData.append(‹ waitTranscoding ›, ‹ true ›);
formData.append(‹ channelId ›, channelId);
formData.append(‹ name ›, name);
formData.append(‹ videofile ›, stream, {
knownLength: size,
filename: ‹ video.mp4 ›,
contentType: ‹ video/mp4 ›,
});
const headers = {
Authorization: 'Bearer ’ + access_token,
…formData.getHeaders(),
‹ Content-Type ›: « multipart/form-data »
};

await axios.post(
${serverUrl}/api/v1/videos/upload,
formData,
{
headers,
maxBodyLength: 10 * 1024 * 1024 * 1024, // 10 GB
maxContentLength: 10 * 1024 * 1024 * 1024, // 10 GB

}

);

The code hangs up and finally nodejs crashes with out of memory (peertube v5, this wasn’t happening on peertube v4)

Could this feature help?

It’s native since v4.3