Skip to main content

getStaticFiles()

v3.3.26
note

此 API 正在移动到 @remotion/studio 包中。建议从 @remotion/studio 导入该 API,而不是从 remotion 导入。

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

🌐 Gets an array containing all files in the public/ folder.
You can reference them by using staticFile().

warning

此功能仅在 Remotion Studio 中以及渲染期间有效,否则它会返回一个空数组。

note

在 Linux 上,只有从 Node.js v19.1.0 开始才支持监视子目录的更改。如果你使用的版本早于此版本,你需要手动刷新 Remotion Studio 的浏览器标签页。

example.ts
import {getStaticFiles, StaticFile} from 'remotion'; import {Video} from '@remotion/media'; 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

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

🌐 Takes no arguments and returns an array of object, each of which have four entries:

  • name:相对于公共文件夹的路径。:::注意 即使在 Windows 上也包含正斜杠 /。:::注意
  • src:带有前缀的路径。每当 Studio 服务器重启时,前缀都会更改。
  • sizeInBytes:文件大小。如果它是一个符号链接,则报告原文件的大小。
  • lastModified:上次修改日期的 Unix 时间戳(毫秒)。

最大文件数

🌐 Maximum files

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

🌐 For performance, only the first 10000 items are fetched and displayed.

更新日志

在 v4.0.64 之前,只显示前 1000 个项目。

🌐 Before v4.0.64, only the first 1000 items were displayed.

兼容性

🌐 Compatibility

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions
Empty array
Empty array
Empty array
If in Studio, otherwise empty array
Empty array

另请参阅

🌐 See also