fix: correct HuggingFace commit API format - header as JSON blob

This commit is contained in:
axibayuit
2025-12-30 19:46:36 +08:00
parent 2943f99e54
commit f768f1cb3b

View File

@@ -109,19 +109,25 @@ export class HuggingFaceAPI {
console.log('Commit URL:', commitUrl);
// 构建 multipart form data
// HuggingFace commit API 格式参考: https://huggingface.co/docs/huggingface.js
const formData = new FormData();
// 添加文件,使用特定的字段名格式
// HuggingFace 期望的格式: file-{index}-{path}
formData.append(`file`, file, filePath);
// header 必须是 JSON blob包含 summary
const header = {
summary: commitMessage,
description: ''
};
formData.append('header', new Blob([JSON.stringify(header)], { type: 'application/json' }));
// 添加操作描述
const operations = JSON.stringify([{
key: 'file',
// 添加文件操作描述
const operations = [{
key: 'file-0',
path: filePath
}]);
formData.append('operations', operations);
formData.append('summary', commitMessage);
}];
formData.append('operations', new Blob([JSON.stringify(operations)], { type: 'application/json' }));
// 添加文件key 必须与 operations 中的 key 匹配
formData.append('file-0', file, filePath.split('/').pop());
const response = await fetch(commitUrl, {
method: 'POST',