|
1 | | -import { ConfigurationError } from "@pipedream/platform"; |
| 1 | +import { getFileStreamAndMetadata } from "@pipedream/platform"; |
2 | 2 | import FormData from "form-data"; |
3 | | -import fs from "fs"; |
4 | 3 | import { LANGUAGE_OPTIONS } from "../../common/constants.mjs"; |
5 | | -import { checkTmp } from "../../common/utils.mjs"; |
6 | 4 | import sonix from "../../sonix.app.mjs"; |
7 | 5 |
|
8 | 6 | export default { |
9 | 7 | key: "sonix-upload-media", |
10 | 8 | name: "Upload Media", |
11 | 9 | description: "Submits new media for processing. [See the documentation](https://sonix.ai/docs/api#new_media)", |
12 | | - version: "0.0.1", |
| 10 | + version: "1.0.0", |
13 | 11 | type: "action", |
14 | 12 | props: { |
15 | 13 | sonix, |
16 | 14 | file: { |
17 | 15 | type: "string", |
18 | | - label: "File", |
19 | | - description: "Path of the audio or video file in /tmp folder. The limit is 100MB using this parameter. For larger files, use **File URL**. `NOTE: Only one of **File** or **File URL** is required.` To upload a file to /tmp folder, please follow the [doc here](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)", |
20 | | - optional: true, |
21 | | - }, |
22 | | - fileUrl: { |
23 | | - type: "string", |
24 | | - label: "File URL", |
25 | | - description: "URL pointing to the audio/video file. `NOTE: Only one of **File** or **File URL** is required.`", |
26 | | - optional: true, |
| 16 | + label: "File Path or URL", |
| 17 | + description: "The audio or video file to upload (max 100MB). Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)", |
27 | 18 | }, |
28 | 19 | language: { |
29 | 20 | type: "string", |
@@ -70,18 +61,17 @@ export default { |
70 | 61 | }, |
71 | 62 | }, |
72 | 63 | async run({ $ }) { |
73 | | - if (!this.file && !this.fileUrl) { |
74 | | - throw new ConfigurationError("You must provite whether **File** or **File URL**."); |
75 | | - } |
76 | | - |
77 | 64 | const formData = new FormData(); |
78 | 65 |
|
79 | | - if (this.file) { |
80 | | - const filePath = checkTmp(this.file); |
81 | | - formData.append("file", fs.createReadStream(filePath)); |
82 | | - } |
| 66 | + const { |
| 67 | + stream, metadata, |
| 68 | + } = await getFileStreamAndMetadata(this.file); |
| 69 | + formData.append("file", stream, { |
| 70 | + contentType: metadata.contentType, |
| 71 | + knownLength: metadata.size, |
| 72 | + filename: metadata.name, |
| 73 | + }); |
83 | 74 |
|
84 | | - this.fileUrl && formData.append("file_url", this.fileUrl); |
85 | 75 | this.language && formData.append("language", this.language); |
86 | 76 | this.name && formData.append("name", this.name); |
87 | 77 | this.transcriptText && formData.append("transcript_text", `${this.transcriptText}`); |
|
0 commit comments