gpt4 book ai didi

node.js - 仅使用 Sails Js 读取上传的文件

转载 作者:太空宇宙 更新时间:2023-11-04 00:58:47 25 4
gpt4 key购买 nike

我想上传一个文件作为缓冲区,使用 utf-8 编码解析字符串减去该字符串的一部分,仅此而已。

我不想将其保存在磁盘上,因为目前它与船长一起 sails 。

https://github.com/balderdashy/skipper

最佳答案

我相信您可以通过上传到临时文件然后从那里读取来完成此操作。例如

// Since we don't provide any other 'opts' arguments to the upload
// method, it will upload our file to a temp directory
skipperFile.upload(function (err, uploadedFiles) {
// If no files were uploaded, respond with an error.
if (uploadedFiles.length === 0) {
return res.badRequest('No file was uploaded');
}
// Now that the file is uploaded, get the file descriptor
var fd = uploadedFiles[0].fd;
fs.readFile(fd, 'utf8', function (err, data) {
// Print the contents of the file as a string here
// and do whatever other string processing you want
console.log(data);
});
});

关于node.js - 仅使用 Sails Js 读取上传的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28118683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com