You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jaseci中将Base64写入文件及保存文件到其文件系统?

在Jaseci中处理Base64数据写入文件及文件系统操作

一、将Base64数据写入文件

在Jaseci中,可通过Jac代码结合内置函数完成Base64数据写入文件,步骤如下:

  1. 解码Base64数据:用base64_decode函数把Base64字符串转成二进制数据
  2. 写入文件:调用file_write函数将解码后的二进制数据写入目标路径

示例代码:

walker write_base64_to_file {
    has base64_str = "你的Base64字符串内容";
    has file_path = "/path/to/your/file.ext"; // 支持本地路径或Jaseci文件系统路径

    // 解码Base64
    decoded_data = base64_decode(base64_str);
    // 二进制模式写入文件
    file_write(file_path, decoded_data, mode="wb");

    std.out("Base64数据已成功写入文件: " + file_path);
}

二、文件保存到Jaseci文件系统

Jaseci自带虚拟文件系统(JSFS),用于统一管理应用文件,核心操作方式如下:

1. 直接写入JSFS

使用jsfs://前缀指定路径,调用file_write即可将内容保存到Jaseci文件系统:

walker save_to_jsfs {
    has file_content = "待保存的文件内容";
    has jsfs_path = "jsfs://my_app/docs/example.txt";

    file_write(jsfs_path, file_content);
    std.out("文件已保存到Jaseci文件系统: " + jsfs_path);
}

2. 本地文件导入JSFS

通过file_copy函数可将本地文件复制到Jaseci文件系统:

walker local_to_jsfs {
    has local_path = "/local/path/to/target_file.txt";
    has jsfs_path = "jsfs://my_app/uploads/target_file.txt";

    file_copy(local_path, jsfs_path);
    std.out("本地文件已同步到Jaseci文件系统");
}

3. 查看JSFS文件列表

用file_list函数可列出指定JSFS目录下的文件:

walker list_jsfs_files {
    has dir_path = "jsfs://my_app/docs/";
    file_list = file_list(dir_path);
    std.out("Jaseci文件系统目录文件列表: ", file_list);
}

三、开发资料参考

无需跳转外部网站,直接通过Jaseci内置渠道获取权威资料:

  • 在Jaseci控制台执行help 函数名(如help file_write、help base64_decode),可查看每个函数的参数说明、使用示例
  • 核心内置函数参考:
    • file_write(path, content, mode="w"): 支持本地/JSFS路径写入,mode可选文本(w)或二进制(wb)模式
    • file_read(path, mode="r"): 读取指定路径文件内容
    • file_copy(src_path, dest_path): 跨本地/JSFS路径复制文件
    • base64_decode(str): Base64字符串转二进制数据
    • base64_encode(data): 二进制数据转Base64字符串

内容的提问来源于stack exchange,提问作者Shawn Jemmott

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 12:15:32