Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.

Commit 477eb08

Browse files
authored
Fix upload file labels (#37)
* fix upload file labels * version bump
1 parent f3a6612 commit 477eb08

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "getindexify",
3-
"version": "0.0.45",
3+
"version": "0.0.46",
44
"description": "This is the TypeScript client for interacting with the Indexify service.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/client.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class IndexifyClient {
358358
fileInput: string | Blob,
359359
labels: Record<string, any> = {},
360360
id?: string
361-
): Promise<string> {
361+
): Promise<string> {
362362
function isBlob(input: any): input is Blob {
363363
return input instanceof Blob;
364364
}
@@ -383,18 +383,11 @@ class IndexifyClient {
383383
// Create form
384384
const FormData = require("form-data");
385385
const formData = new FormData();
386+
formData.append("labels", JSON.stringify(labels));
386387
formData.append("file", fs.createReadStream(fileInput as string)); //stream
387388

388-
// Append labels to the form data
389-
Object.keys(labels).forEach((key) => {
390-
formData.append(key, labels[key]);
391-
});
392-
393389
// Upload File
394390
const res = await this.client.post("upload_file", formData, {
395-
headers: {
396-
...formData.getHeaders(),
397-
},
398391
params,
399392
});
400393
return res.data.content_id;
@@ -403,15 +396,10 @@ class IndexifyClient {
403396
if (!isBlob(fileInput)) {
404397
throw Error("Expected blob");
405398
}
406-
407399
// Create form
408400
const formData = new FormData();
409-
formData.append("file", fileInput); //blob
410-
411-
// Append labels to the form data
412-
Object.keys(labels).forEach((key) => {
413-
formData.append(key, labels[key]);
414-
});
401+
formData.append("labels", JSON.stringify(labels));
402+
formData.append("file", fileInput);
415403

416404
// Upload File
417405
const res = await this.client.post("/upload_file", formData, {

tests/client.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ test("getExtractedContent", async () => {
174174

175175
let content;
176176

177-
content = await client.getExtractedContent({ parent_id: "idontexist" });
177+
content = await client.getExtractedContent({ parentId: "idontexist" });
178178
expect(content.length).toBe(0);
179179

180-
content = await client.getExtractedContent({ labels_eq: "source:test" });
180+
content = await client.getExtractedContent({ labelsEq: "source:test" });
181181
expect(content.length).toBe(2);
182182
expect(content[0].content_url).toContain("http://");
183183

184-
content = await client.getExtractedContent({ labels_eq: "source:nothing" });
184+
content = await client.getExtractedContent({ labelsEq: "source:nothing" });
185185
expect(content.length).toBe(0);
186186
});
187187

@@ -250,7 +250,7 @@ test("downloadContent", async () => {
250250
]);
251251

252252
const content = await client.getExtractedContent({
253-
labels_eq: "source:testdownload",
253+
labelsEq: "source:testdownload",
254254
});
255255
expect(content.length).toBeGreaterThanOrEqual(1);
256256

0 commit comments

Comments
 (0)