fix: use string fields instead of JSON blob for HuggingFace commit API

This commit is contained in:
axibayuit
2025-12-30 19:52:36 +08:00
parent f768f1cb3b
commit 2f1e9df5a0

View File

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