Skip to main content

getStaticFiles()v4.0.144

获取包含public/文件夹中所有文件的数组。您可以通过使用staticFile()来引用它们。

note

此 API 正在从remotion包中移动。
请优先使用此 API 而不是旧的 API。

note

在 Remotion Studio 之外的环境中,此 API 返回一个空数组。

note

在 Linux 上,仅支持从 Node.js v19.1.0 开始监视子目录中的更改。如果您使用早于该版本的版本,则需要手动刷新 Remotion Studio 浏览器选项卡。

example.ts
tsx
import { getStaticFiles, StaticFile } from "@remotion/studio";
import { Video } from "remotion";
 
const files = getStaticFiles();
/*
[
{
"name": "video.mp4",
"src": "/static-7n5spa/video.mp4",
"sizeInBytes": 432944,
"lastModified": 1670170466865
},
{
"name": "assets/data.json",
"src": "/static-7n5spa/assets/data.json",
"sizeInBytes": 1311,
"lastModified": 1670170486089
},
]
*/
 
// ❗ Don't pass the `name` directly to the `src` of a media element
const videoName = files[0].name;
 
// ✅ Wrap it in staticFile() instead or use `src`
const videoSrc = files[0].src;
 
// Find a file by it's name and import it
const data = files.find((f) => {
return f.name === "video.mp4";
}) as StaticFile; // Use `as StaticFile` to assert the file exists
 
// Use the `src` property to get a src to pass to a media element
<Video src={data.src} />;
example.ts
tsx
import { getStaticFiles, StaticFile } from "@remotion/studio";
import { Video } from "remotion";
 
const files = getStaticFiles();
/*
[
{
"name": "video.mp4",
"src": "/static-7n5spa/video.mp4",
"sizeInBytes": 432944,
"lastModified": 1670170466865
},
{
"name": "assets/data.json",
"src": "/static-7n5spa/assets/data.json",
"sizeInBytes": 1311,
"lastModified": 1670170486089
},
]
*/
 
// ❗ Don't pass the `name` directly to the `src` of a media element
const videoName = files[0].name;
 
// ✅ Wrap it in staticFile() instead or use `src`
const videoSrc = files[0].src;
 
// Find a file by it's name and import it
const data = files.find((f) => {
return f.name === "video.mp4";
}) as StaticFile; // Use `as StaticFile` to assert the file exists
 
// Use the `src` property to get a src to pass to a media element
<Video src={data.src} />;

API

不接受任何参数,并返回一个对象数组,每个对象有四个条目:

  • name:相对于 public 文件夹的路径。

    note

    即使在 Windows 上,也包含正斜杠 /

    note
  • src:带有前缀的路径。每当 Studio 服务器重新启动时,前缀都会更改。

  • sizeInBytes:文件大小。如果是符号链接,则报告原始文件的文件大小。

  • lastModified:Unix 时间戳的最后修改日期(以毫秒为单位)。

最大文件数

为了性能考虑,只获取和显示前 10000 个项目。

另请参阅