所以我想上传大文件到远程,所以我正在创建 ReadStream
const stream = fs.createReadStream(req.file.path);
async uploadStream(stream: NodeJS.ReadableStream, filePath: string) {
const dir = path.dirname(filePath);
if (!(await this.exists(dir))) {
await this.mkdir(dir);
}
await this.putStream(stream, filePath);
return this.url(filePath);
}
async putStream(stream: NodeJS.ReadableStream, filePath: string) {
await this.connect();
const normFIlePath = this.normalizePath(filePath);
await this.sftp.put(stream, normFIlePath).catch(e => {
console.log(e);
});
await this.disconnect()
}
Run Code Online (Sandbox Code Playgroud)
上传后,我将数据保存到数据库并返回文件 url
file = await fileRepo.save(file);
res.send({
id: file.data.itemId,
src: file.url
});
Run Code Online (Sandbox Code Playgroud)
文件正在上传,但之后返回错误:
(node:18) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Run Code Online (Sandbox Code Playgroud) 我试图按第一个字符对标签进行分组
return $tags->select('id', 'title')
->orderBy('title','asc')
->groupBy(function($item, $key) {
return substr($item['title'], 1, 1);
})
->get();
Run Code Online (Sandbox Code Playgroud)
但它返回此错误
strtolower()期望参数1为字符串,给定对象