switched to buffer input for uploading
This commit is contained in:
@ -34,7 +34,7 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="nextcloud-webdav-list">
|
||||
<p>Connects to a Nextcloud server and lists directory content of a given path)</p>
|
||||
<p>Connects to a Nextcloud/WebDav server and lists directory content of a given path)</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
@ -106,7 +106,7 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="nextcloud-webdav-out">
|
||||
<p>Connects to a Nextcloud server and downloads a file and sends it to the output</p>
|
||||
<p>Connects to a Nextcloud/WebDav server and downloads a file and sends it to the output</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
@ -173,18 +173,17 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="nextcloud-webdav-in">
|
||||
<p>Connects to a Nextcloud server and uploads a file to a given directory</p>
|
||||
<p>Connects to a Nextcloud/WebDav server and uploads a file to a given directory</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload
|
||||
<span class="property-type">any</span>
|
||||
<span class="property-type">Binary buffer</span>
|
||||
</dt>
|
||||
<dd> Incoming message triggers receiving a list containing a directory content. Any payload
|
||||
is possible. </dd>
|
||||
<dd> The payload should contain the file which should be uploaded in a binary buffer </dd>
|
||||
<dt class="optional">filename <span class="property-type">string</span></dt>
|
||||
<dd> The filename should be an absolute path, otherwise it will be relative to the working
|
||||
directory of the Node-RED process.</dd>
|
||||
<dd> A filename can be specified on incoming message or in nodes properties.
|
||||
Saves the uploaded file with the given name. The property should also include the file extension.</dd>
|
||||
<dt class="optional">directory <span class="property-type">string</span></dt>
|
||||
<dd> A directory can be specified on incoming message or in nodes properties. Uploads the
|
||||
file to the users root directory if not set.</dd>
|
||||
|
||||
22
nextcloud.js
22
nextcloud.js
@ -2,9 +2,10 @@ module.exports = function (RED) {
|
||||
const dav = require('dav')
|
||||
const webdav = require('webdav')
|
||||
const fs = require('fs')
|
||||
const IcalExpander = require('ical-expander')
|
||||
const moment = require('moment')
|
||||
const https = require('https')
|
||||
const rootCas = require('ssl-root-cas').create();
|
||||
|
||||
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
|
||||
|
||||
|
||||
|
||||
@ -83,14 +84,16 @@ module.exports = function (RED) {
|
||||
const node = this
|
||||
|
||||
node.on('input', (msg) => {
|
||||
|
||||
// Read upload file
|
||||
let filename = node.filename
|
||||
if (msg.filename) {
|
||||
filename = msg.filename
|
||||
filename = msg.filename;
|
||||
}
|
||||
const name = filename.substr((filename.lastIndexOf('/') + 1), filename.length)
|
||||
const file = fs.readFileSync(filename)
|
||||
const file = msg.payload;
|
||||
// Set upload directory
|
||||
|
||||
let directory = '/'
|
||||
if (msg.directory) {
|
||||
directory += msg.directory + '/'
|
||||
@ -99,20 +102,23 @@ module.exports = function (RED) {
|
||||
}
|
||||
directory = directory.replace('//', '/')
|
||||
|
||||
const webDavUri = node.server.address + '/remote.php/webdav/'
|
||||
const client = webdav(webDavUri, node.server.credentials.user, node.server.credentials.pass)
|
||||
|
||||
// check option for self signed certs
|
||||
const option = {}
|
||||
if (node.server.insecure) {
|
||||
option.agent = new https.Agent({ rejectUnauthorized: false })
|
||||
}
|
||||
|
||||
const webDavUri = node.server.address + '/remote.php/webdav/'
|
||||
const client = webdav(webDavUri, node.server.credentials.user, node.server.credentials.pass)
|
||||
|
||||
|
||||
|
||||
client.putFileContents(directory + name, file, { format: 'binary' }, option)
|
||||
.then(function (contents) {
|
||||
console.log(contents)
|
||||
node.send({ 'payload': JSON.parse(contents) })
|
||||
}, function () {
|
||||
}, function (e) {
|
||||
console.error(e);
|
||||
node.error('Nextcloud:WebDAV -> send file went wrong.')
|
||||
})
|
||||
})
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
"dav": "^1.8.0",
|
||||
"ical-expander": "^2.0.0",
|
||||
"moment": "^2.24.0",
|
||||
"ssl-root-cas": "^1.3.1",
|
||||
"webdav": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user