Skip to content

Commit 486ec3f

Browse files
committed
add: roboflow, salesforce_rest_api
1 parent 371c5d4 commit 486ec3f

File tree

6 files changed

+39
-48
lines changed

6 files changed

+39
-48
lines changed

components/roboflow/actions/classify-image/classify-image.mjs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import roboflow from "../../roboflow.app.mjs";
2-
import { getFileStream } from "@pipedream/platform";
2+
import utils from "../../common/utils.mjs";
33

44
export default {
55
key: "roboflow-classify-image",
66
name: "Classify Image",
77
description: "Run inference on classification models hosted on Roboflow. [See the documentation](https://docs.roboflow.com/deploy/hosted-api/classification).",
8-
version: "0.1.0",
8+
version: "1.0.0",
99
type: "action",
1010
props: {
1111
roboflow,
@@ -32,23 +32,14 @@ export default {
3232
},
3333
},
3434
async run({ $ }) {
35-
const stream = getFileStream(this.filePath);
36-
const chunks = [];
37-
for await (const chunk of stream) {
38-
chunks.push(chunk);
39-
}
40-
const data = Buffer.concat(chunks).toString("base64");
41-
42-
const args = {
35+
const response = await this.roboflow.classifyImage({
4336
datasetId: this.datasetId,
4437
$,
45-
data,
38+
data: await utils.getBase64File(this.filePath),
4639
headers: {
4740
"Content-Type": "application/x-www-form-urlencoded",
4841
},
49-
};
50-
51-
const response = await this.roboflow.classifyImage(args);
42+
});
5243

5344
if (!response?.error) {
5445
$.export("$summary", "Successfully classified image.");

components/roboflow/actions/detect-object-from-image/detect-object-from-image.mjs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import roboflow from "../../roboflow.app.mjs";
2-
import { getFileStream } from "@pipedream/platform";
2+
import utils from "../../common/utils.mjs";
33

44
export default {
55
key: "roboflow-detect-object-from-image",
66
name: "Detect Object From Image",
77
description: "Run inference on your object detection models hosted on Roboflow. [See the documentation](https://docs.roboflow.com/deploy/hosted-api/object-detection).",
8-
version: "0.1.0",
8+
version: "1.0.0",
99
type: "action",
1010
props: {
1111
roboflow,
@@ -32,23 +32,14 @@ export default {
3232
},
3333
},
3434
async run({ $ }) {
35-
const stream = getFileStream(this.filePath);
36-
const chunks = [];
37-
for await (const chunk of stream) {
38-
chunks.push(chunk);
39-
}
40-
const data = Buffer.concat(chunks).toString("base64");
41-
42-
const args = {
35+
const response = await this.roboflow.detectObject({
4336
datasetId: this.datasetId,
4437
$,
45-
data,
38+
data: await utils.getBase64File(this.filePath),
4639
headers: {
4740
"Content-Type": "application/x-www-form-urlencoded",
4841
},
49-
};
50-
51-
const response = await this.roboflow.detectObject(args);
42+
});
5243

5344
if (!response?.error) {
5445
$.export("$summary", "Successfully ran object detection inference model on image.");

components/roboflow/actions/upload-image/upload-image.mjs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import roboflow from "../../roboflow.app.mjs";
2-
import { getFileStream } from "@pipedream/platform";
2+
import { getFileStreamAndMetadata } from "@pipedream/platform";
33
import utils from "../../common/utils.mjs";
44
import FormData from "form-data";
55

@@ -31,29 +31,26 @@ export default {
3131
},
3232
},
3333
async run({ $ }) {
34-
const args = {
35-
projectId: utils.extractSubstringAfterSlash(this.projectId),
36-
$,
37-
};
38-
3934
const formData = new FormData();
4035
if (this.name) {
4136
formData.append("name", this.name);
4237
}
4338

44-
if (this.filePath.startsWith("http")) {
45-
args.params = {
46-
image: this.filePath,
47-
name: this.name,
48-
};
49-
} else {
50-
const stream = getFileStream(this.filePath);
51-
formData.append("file", stream);
52-
args.data = formData;
53-
args.headers = formData.getHeaders();
54-
}
39+
const {
40+
stream, metadata,
41+
} = await getFileStreamAndMetadata(this.filePath);
42+
formData.append("file", stream, {
43+
contentType: metadata.contentType,
44+
knownLength: metadata.size,
45+
filename: metadata.name,
46+
});
5547

56-
const response = await this.roboflow.uploadImage(args);
48+
const response = await this.roboflow.uploadImage({
49+
$,
50+
projectId: utils.extractSubstringAfterSlash(this.projectId),
51+
data: formData,
52+
headers: formData.getHeaders(),
53+
});
5754

5855
if (!response?.error) {
5956
$.export("$summary", "Successfully uploaded image.");

components/roboflow/common/utils.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getFileStream } from "@pipedream/platform";
2+
13
function extractSubstringAfterSlash(str) {
24
const match = str.match(/\/(.*)/);
35
if (match && match[1]) {
@@ -7,6 +9,16 @@ function extractSubstringAfterSlash(str) {
79
}
810
}
911

12+
async function getBase64File(filePath) {
13+
const stream = await getFileStream(filePath);
14+
const chunks = [];
15+
for await (const chunk of stream) {
16+
chunks.push(chunk);
17+
}
18+
return Buffer.concat(chunks).toString("base64");
19+
}
20+
1021
export default {
1122
extractSubstringAfterSlash,
23+
getBase64File,
1224
};

components/roboflow/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/roboflow",
3-
"version": "0.2.0",
3+
"version": "1.0.0",
44
"description": "Pipedream Roboflow Components",
55
"main": "roboflow.app.mjs",
66
"keywords": [

components/salesforce_rest_api/common/sobjects/attachment.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
},
1010
filePathOrContent: {
1111
type: "string",
12-
label: "File Path or URL",
12+
label: "File Path, URL or Content",
1313
description: "The file to attach. Provide either a file URL, a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`), or base64-encoded file data.",
1414
},
1515
ContentType: {

0 commit comments

Comments
 (0)