Skip to content

Commit 4b73e15

Browse files
add file streaming
1 parent de3be06 commit 4b73e15

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

components/microsoft_onedrive/actions/upload-file/upload-file.mjs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import onedrive from "../../microsoft_onedrive.app.mjs";
22
import { ConfigurationError } from "@pipedream/platform";
33
import fs from "fs";
4-
import { fileTypeFromBuffer } from "file-type";
4+
import { fileTypeFromStream } from "file-type";
55

66
export default {
77
name: "Upload File",
88
description: "Upload a file to OneDrive. [See the documentation](https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online)",
99
key: "microsoft_onedrive-upload-file",
10-
version: "0.1.1",
10+
version: "0.1.2",
1111
type: "action",
1212
props: {
1313
onedrive,
@@ -39,18 +39,22 @@ export default {
3939
throw new ConfigurationError("You must specify the **Upload Folder ID**.");
4040
}
4141

42-
const data = fs.readFileSync(filePath);
42+
let stream = fs.createReadStream(filePath);
4343
let name = filename;
44+
4445
if (!filename.includes(".")) {
45-
const fileType = await fileTypeFromBuffer(data);
46-
const extension = fileType?.ext || "";
46+
const fileTypeResult = await fileTypeFromStream(stream);
47+
const extension = fileTypeResult?.ext || "";
4748
name = `${filename}.${extension}`;
49+
50+
stream.destroy();
51+
stream = fs.createReadStream(filePath);
4852
}
4953

5054
const response = await this.onedrive.uploadFile({
5155
uploadFolderId,
5256
name,
53-
data,
57+
data: stream,
5458
$,
5559
});
5660

0 commit comments

Comments
 (0)