Skip to content

Commit ab1b77a

Browse files
committed
fixup upload file
1 parent 5639ffd commit ab1b77a

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

OpenFlowNodeRED/src/nodered/nodes/api.html

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,16 @@
15151515
<input type="hidden" id="node-input-mimeTypetype">
15161516
<input style="width:70%" type="text" id="node-input-mimeType" placeholder="Mimetype of file">
15171517
</div>
1518+
<div class="form-row">
1519+
<label><i class="fa fa-tag"></i> File Content</label>
1520+
<input type="hidden" id="node-input-contenttype">
1521+
<input style="width:70%" type="text" id="node-input-content" placeholder="Base64 encoded file content">
1522+
</div>
1523+
<div class="form-row">
1524+
<label><i class="fa fa-list"></i> DB Entity</label>
1525+
<input type="hidden" id="node-input-entitytype">
1526+
<input style="width:70%" type="text" id="node-input-entity">
1527+
</div>
15181528
<div class="form-row">
15191529
<label><i class="fa fa-tag"></i> Name</label>
15201530
<input type="text" id="node-input-name" placeholder="Node name">
@@ -1523,8 +1533,6 @@
15231533
<script type="text/x-red" data-help-name="api upload file">
15241534
Upload a file to API/GridFS<br>
15251535
msg.payload should be a base64 encode string of the file.<br>
1526-
you can set filename using msg.filename<br>
1527-
you can set mimeType using msg.mimeType<br>
15281536
to save data with the file set msg.metadata to and javascript object<br>
15291537
</script>
15301538
<script type="text/javascript">
@@ -1534,10 +1542,14 @@
15341542
paletteLabel: 'upload',
15351543
icon: "font-awesome/fa-upload",
15361544
defaults: {
1537-
filename: { value: "", validate: validate("filenametype"), required: true },
1545+
filename: { value: "filename", validate: validate("filename"), required: true },
15381546
filenametype: { value: "" },
1539-
mimeType: { value: "", validate: validate("mimeTypetype"), required: true },
1547+
content: { value: "payload", validate: validate("content"), required: true },
1548+
contenttype: { value: "" },
1549+
mimeType: { value: "", validate: RED.validators.typedInput("mimeTypetype") },
15401550
mimeTypetype: { value: "" },
1551+
entity: { value: "result", validate: RED.validators.typedInput("mimeTypetype") },
1552+
entitytype: { value: "" },
15411553
name: { value: "" }
15421554
},
15431555
inputs: 1,
@@ -1551,16 +1563,28 @@
15511563
oneditprepare: function () {
15521564
if (this.filenametype === 'val') $("#node-input-filenametype").val('str');
15531565
$("#node-input-filename").typedInput({
1554-
default: 'str',
1566+
default: 'msg',
15551567
typeField: $("#node-input-filenametype"),
15561568
types: ['msg', 'str', 'flow', 'global', 'json']
15571569
});
1570+
if (this.contenttype === 'val') $("#node-input-contenttype").val('str');
1571+
$("#node-input-content").typedInput({
1572+
default: 'msg',
1573+
typeField: $("#node-input-contenttype"),
1574+
types: ['msg']
1575+
});
15581576
if (this.mimeTypetype === 'val') $("#node-input-mimeTypetype").val('str');
15591577
$("#node-input-mimeType").typedInput({
15601578
default: 'str',
15611579
typeField: $("#node-input-mimeTypetype"),
15621580
types: ['msg', 'str', 'flow', 'global', 'json']
15631581
});
1582+
if (this.entitytype === 'val') $("#node-input-entitytype").val('str');
1583+
$("#node-input-entity").typedInput({
1584+
default: 'msg',
1585+
typeField: $("#node-input-entitytype"),
1586+
types: ['msg']
1587+
});
15641588
},
15651589
});
15661590
</script>

OpenFlowNodeRED/src/nodered/nodes/api_nodes.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@ export interface Iuploadload_file {
11691169
filename: string;
11701170
mimeType: string;
11711171
name: string;
1172+
content: string;
11721173
}
11731174
export class upload_file {
11741175
public node: Red = null;
@@ -1187,18 +1188,17 @@ export class upload_file {
11871188
const jwt = msg.jwt;
11881189
const filename = await Util.EvaluateNodeProperty<string>(this, msg, "filename");
11891190
const mimeType = await Util.EvaluateNodeProperty<string>(this, msg, "mimeType");
1191+
const filecontent = await Util.EvaluateNodeProperty<string>(this, msg, "content");
11901192
let priority: number = 1;
11911193
if (!NoderedUtil.IsNullEmpty(msg.priority)) { priority = msg.priority; }
11921194

11931195
this.node.status({ fill: "blue", shape: "dot", text: "Saving file" });
1194-
const file = await NoderedUtil.SaveFile(filename, mimeType, msg.metadata, msg.payload, jwt, priority);
1196+
const file = await NoderedUtil.SaveFile(filename, mimeType, msg.metadata, filecontent, jwt, priority);
11951197
if (!NoderedUtil.IsNullEmpty(file.error)) { throw new Error(file.error); }
1196-
msg.filename = file.filename;
1197-
msg.id = file.id;
1198-
msg.mimeType = file.mimeType;
1199-
msg.metadata = file.metadata;
1200-
msg.payload = file;
12011198

1199+
if (!NoderedUtil.IsNullEmpty(this.config.filename)) Util.SetMessageProperty(msg, this.config.filename, file.filename);
1200+
if (!NoderedUtil.IsNullEmpty(this.config.mimeType)) Util.SetMessageProperty(msg, this.config.mimeType, file.mimeType);
1201+
if (!NoderedUtil.IsNullEmpty(this.config.content)) Util.SetMessageProperty(msg, this.config.content, file);
12021202
this.node.send(msg);
12031203
this.node.status({});
12041204
} catch (error) {

0 commit comments

Comments
 (0)