首页 > 解决方案 > Node-Red Dropbox 节点

问题描述

我正在使用 node-red-node-dropbox 并让我的流程执行以下操作:

  1. 使用文件访问检查文件是否存在,如果存在,请上传。
  2. 文件上传后,收到更改通知,获取名称和路径,并删除本地文件(如果存在)。下面是我用来调试的测试低点。 在此处输入图像描述

结果:如果文件存在,则将文件上传到目录。然后被删除。所有工作都按计划进行。问题是当我转到投递箱上的文件时,该文件的大小只有几个字节,而不是预期的 KB 或有时 MB。我对类似问题做了一些研究,发现如下: Laravel Dropbox API v2 - Empty File on Upload

现在我要说,我不是程序员。我正在做一个家庭项目,并试图将延时 GIF 从我的本地 Rpi 移动到 Dropbox 文件夹。

任何帮助都非常感谢。如果有更新、破解、解决方法,我会采取任何措施。

这是我的测试流程:

[{"id":"4fd3d436.eb8fcc","type":"tab","label":"DropBox","disabled":false,"info":""},{"id":"8e054ce8.884b","type":"function","z":"4fd3d436.eb8fcc","name":"name gif","func":"msg.path = \"/home/pi/.node-red/static/gif/old/\";\n\nmsg.filename = \"img20201027_144920.gif\";\n\nmsg.payload = msg.path + msg.filename\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":180,"wires":[["15144f44.cf7dc1"]]},{"id":"2377960c.da806a","type":"dropbox out","z":"4fd3d436.eb8fcc","dropbox":"","filename":"","localFilename":"","name":"Dropbox","x":1020,"y":180,"wires":[]},{"id":"7a40742d.26a4dc","type":"inject","z":"4fd3d436.eb8fcc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":180,"wires":[["8e054ce8.884b"]]},{"id":"41e83491.8e6dbc","type":"dropbox in","z":"4fd3d436.eb8fcc","dropbox":"","filepattern":"","name":"","x":220,"y":280,"wires":[["5941e355.c66b9c"]]},{"id":"3003a90.8933658","type":"function","z":"4fd3d436.eb8fcc","name":"gif name","func":"msg.path = \"/home/pi/.node-red/static/gif/old/\";\n\nmsg.filename = msg.file;\n\nmsg.payload = msg.path + msg.filename\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":280,"wires":[["3eeef854.713178"]]},{"id":"5941e355.c66b9c","type":"delay","z":"4fd3d436.eb8fcc","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":280,"wires":[["3003a90.8933658"]]},{"id":"9d041a38.f66f48","type":"exec","z":"4fd3d436.eb8fcc","command":"rm ","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":1110,"y":280,"wires":[[],[],[]]},{"id":"77b26b64.855c54","type":"comment","z":"4fd3d436.eb8fcc","name":"Delete local file","info":"Once the file is on dropbox, get the path and file name and delete the local file then","x":240,"y":240,"wires":[]},{"id":"15144f44.cf7dc1","type":"fs-ops-access","z":"4fd3d436.eb8fcc","name":"","path":"path","pathType":"msg","filename":"filename","filenameType":"msg","read":true,"write":true,"throwerror":false,"x":590,"y":180,"wires":[["f0f07147.1b318"],[]]},{"id":"f0f07147.1b318","type":"change","z":"4fd3d436.eb8fcc","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":180,"wires":[["2377960c.da806a"]]},{"id":"22c79cc5.761a64","type":"comment","z":"4fd3d436.eb8fcc","name":"Upload local file","info":"Check if the file exists locally. If it does, then upload it to dropbox","x":240,"y":140,"wires":[]},{"id":"3eeef854.713178","type":"fs-ops-access","z":"4fd3d436.eb8fcc","name":"","path":"path","pathType":"msg","filename":"filename","filenameType":"msg","read":true,"write":true,"throwerror":false,"x":730,"y":280,"wires":[["2ef8b77b.eb0658"],[]]},{"id":"2ef8b77b.eb0658","type":"change","z":"4fd3d436.eb8fcc","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":280,"wires":[["9d041a38.f66f48"]]}]

标签: dropbox-apinode-red

解决方案


我更改了流程并添加了 readdir 以创建目录中所有文件的列表。

更新流程

readdir 的设置是:

读取目录设置

我基本上指向我所有文件所在的目录,并通过将它们设置为有效负载的 msg.filename 属性一次上传一个。这就是 Dropbox 节点所需要的。现在效果很好。


推荐阅读