Spaces:
Running
Running
Fix survey submit: use correct HF commit API JSON format with files array
Browse filesCo-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- app/api/survey-submit/route.ts +13 -13
app/api/survey-submit/route.ts
CHANGED
|
@@ -34,26 +34,26 @@ export async function POST(request: Request) {
|
|
| 34 |
const content = JSON.stringify(surveyData, null, 2)
|
| 35 |
|
| 36 |
try {
|
| 37 |
-
// Use the HuggingFace Hub commit API
|
| 38 |
-
// The API expects: a header part (JSON with summary + operations metadata)
|
| 39 |
-
// followed by the file content, all in one multipart request.
|
| 40 |
const commitUrl = `${HF_API}/${HF_REPO}/commit/main`
|
| 41 |
|
| 42 |
-
const header = JSON.stringify({
|
| 43 |
-
summary: `Survey response from ${participant} at ${timestamp}`,
|
| 44 |
-
operations: [{ operation: "create", path: filename }],
|
| 45 |
-
})
|
| 46 |
-
|
| 47 |
-
const formData = new FormData()
|
| 48 |
-
formData.append("header", new Blob([header], { type: "application/json" }))
|
| 49 |
-
formData.append("file", new Blob([content], { type: "application/json" }), filename)
|
| 50 |
-
|
| 51 |
const res = await fetch(commitUrl, {
|
| 52 |
method: "POST",
|
| 53 |
headers: {
|
| 54 |
Authorization: `Bearer ${token}`,
|
|
|
|
| 55 |
},
|
| 56 |
-
body:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
})
|
| 58 |
|
| 59 |
if (!res.ok) {
|
|
|
|
| 34 |
const content = JSON.stringify(surveyData, null, 2)
|
| 35 |
|
| 36 |
try {
|
| 37 |
+
// Use the HuggingFace Hub commit API (legacy JSON format)
|
|
|
|
|
|
|
| 38 |
const commitUrl = `${HF_API}/${HF_REPO}/commit/main`
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
const res = await fetch(commitUrl, {
|
| 41 |
method: "POST",
|
| 42 |
headers: {
|
| 43 |
Authorization: `Bearer ${token}`,
|
| 44 |
+
"Content-Type": "application/json",
|
| 45 |
},
|
| 46 |
+
body: JSON.stringify({
|
| 47 |
+
summary: `Survey response from ${participant} at ${timestamp}`,
|
| 48 |
+
description: "",
|
| 49 |
+
files: [
|
| 50 |
+
{
|
| 51 |
+
path: filename,
|
| 52 |
+
content: content,
|
| 53 |
+
encoding: "utf-8",
|
| 54 |
+
},
|
| 55 |
+
],
|
| 56 |
+
}),
|
| 57 |
})
|
| 58 |
|
| 59 |
if (!res.ok) {
|