diff --git a/src/objectManager.js b/src/objectManager.js index 14bd7f3..b53eea1 100644 --- a/src/objectManager.js +++ b/src/objectManager.js @@ -133,7 +133,7 @@ class ObjectManager { * // Upload Directory * await objectManager.upload("my-first-directory", [ * { - * path: "/testObjects/1.txt", + * path: "/testObjects/1.txt", // Virtual Path to store contents at within IPFS Folder/Directory * content: Buffer.from("upload test object", "utf-8"), * }, * { @@ -206,7 +206,8 @@ class ObjectManager { }); let createFilePromises = []; const queue = new PQueue({ concurrency: 50 }); - for (const entry of source) { + for (let entry of source) { + entry.path = entry.path.startsWith("/") ? entry.path : `/${entry.path}`; if (entry.content === null) { continue; } diff --git a/test/objectManager.spec.cjs b/test/objectManager.spec.cjs index e87b98b..7ea28d8 100644 --- a/test/objectManager.spec.cjs +++ b/test/objectManager.spec.cjs @@ -157,6 +157,38 @@ test("upload directory", async () => { } }); +test("upload directory relative paths", async () => { + // Create Bucket `create-object-test-pass + const uploadDirectoryTestBucket = `${TEST_PREFIX}-create-directory-relative-test-pass`; + await createBucket(uploadDirectoryTestBucket); + + try { + // Upload object `create-object-test` + const uploaded = await uploadObject( + uploadDirectoryTestBucket, + `create-directory-relative-test`, + [ + { + path: "testObjects/1.txt", + content: Buffer.from("upload test object", "utf-8"), + }, + { + path: "testObjects/deep/1.txt", + content: Buffer.from("upload deep test object", "utf-8"), + }, + { + path: "topLevel.txt", + content: Buffer.from("upload top level test object", "utf-8"), + }, + ], + ); + assert.strictEqual(uploaded, true); + await deleteObject(uploadDirectoryTestBucket, `create-directory-relative-test`); + } finally { + await deleteBucket(uploadDirectoryTestBucket); + } +}); + test("download object", async () => { // Create bucket `download-object-test-pass` const downloadTestBucket = `${TEST_PREFIX}-download-object-test-pass`;