getStaticFiles()v4.0.144
获取包含 public/ 文件夹中所有文件的数组。你可以通过使用 staticFile() 来引用它们。
🌐 Gets an array containing all files in the public/ folder. You can reference them by using staticFile().
note
此 API 正从 remotion 包中移出。
建议优先使用此 API,而不是旧的 API。
note
在 Remotion Studio 之外的环境中,此 API 返回一个空数组。
note
在 Linux 上,只有从 Node.js v19.1.0 开始才支持监视子目录的更改。如果你使用的版本早于此版本,你需要手动刷新 Remotion Studio 的浏览器标签页。
example.tsimport {getStaticFiles ,StaticFile } from '@remotion/studio'; import {Video } from '@remotion/media'; constfiles =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 constvideoName =files [0].name ; // ✅ Wrap it in staticFile() instead or use `src` constvideoSrc =files [0].src ; // Find a file by it's name and import it constdata =files .find ((f ) => { returnf .name === 'video.mp4'; }) asStaticFile ; // 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.
另请参阅
🌐 See also