gpt4 book ai didi

node.js - Docker 中 Apollo 服务器上传文件失败

转载 作者:太空宇宙 更新时间:2023-11-03 22:04:15 26 4
gpt4 key购买 nike

UPD 几个小时后,我有了一个好主意,在 docker 中尝试另一个 Node 版本。 Alpine 给出了这个错误,而 10.15 工作正常。

我的解析器中有以下函数来通过 apollo graphql 上传文件

return new Promise(function(resolve, reject) {
const { createReadStream, filename, mimetype } = file
if (!(mimetype === 'image/png' || mimetype === 'image/jpeg' || mimetype === 'image/jpg')){
const error = new Error('Forbidden file type ', mimetype)
error.code = 415
reject(error)
}

const savedFileName = uuidv4()+path.extname(filename)
const savedFile = path.join(__dirname, '..', 'images', subDir, savedFileName)
const imagePath = path.join('/images', subDir, savedFileName).replace(/\\/g, "/")

const readStream = createReadStream()

const writeStream = fs.createWriteStream(savedFile, { flags : 'w' });
readStream.pipe(writeStream)

readStream.on('error', () => console.log('reading error'))
writeStream.on('finish', () => resolve({file: savedFile, imageUrl: imagePath}))
writeStream.on('error', (error) => {

//const err = new Error('Error writing file')
//error.code = 422
reject(error)
})

在我的Windows开发环境中运行良好。我尝试为我的项目创建 docker 容器,但此代码段失败并出现错误:

internal/fs/streams.js:120
node_1 | function _openReadFs(stream) {
node_1 | ^
node_1 |
node_1 | RangeError: Maximum call stack size exceeded
node_1 | at _openReadFs (internal/fs/streams.js:120:21)
node_1 | at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
node_1 | at ReadStream.deprecated [as open] (internal/util.js:70:15)
node_1 | at ReadStream.open (/app/node_modules/fs-capacitor/lib/index.js:90:11)
node_1 | at _openReadFs (internal/fs/streams.js:123:12)
node_1 | at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
node_1 | at ReadStream.deprecated [as open] (internal/util.js:70:15)
node_1 | at ReadStream.open (/app/node_modules/fs-capacitor/lib/index.js:90:11)
node_1 | at _openReadFs (internal/fs/streams.js:123:12)
node_1 | at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
node_1 | at ReadStream.deprecated [as open] (internal/util.js:70:15)
node_1 | at ReadStream.open (/app/node_modules/fs-capacitor/lib/index.js:90:11)
node_1 | at _openReadFs (internal/fs/streams.js:123:12)
node_1 | at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
node_1 | at ReadStream.deprecated [as open] (internal/util.js:70:15)
node_1 | at ReadStream.open (/app/node_modules/fs-capacitor/lib/index.js:90:11)
node_1 | at _openReadFs (internal/fs/streams.js:123:12)
node_1 | at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
node_1 | at ReadStream.deprecated [as open] (internal/util.js:70:15)
node_1 | at ReadStream.open (/app/node_modules/fs-capacitor/lib/index.js:90:11)
node_1 | at _openReadFs (internal/fs/streams.js:123:12)
node_1 | at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
node_1 | [nodemon] app crashed - waiting for file changes before starting...

我是 Docker 新手,特别是 Linux 新手。也许 Linux 中的读取和管道处理方式有所不同。但我不明白该去哪里看。是Apollo的问题还是docker的问题还是我的linux知识贫乏的问题。将不胜感激任何建议。

最佳答案

这是由于 Node 弃用了一些内部流 API,请参阅 DEP0135: WriteStream.open() and ReadStream.open() are internal .

WriteStream.open() and ReadStream.open() are undocumented internal APIs that do not make sense to use in userland. File streams should always be opened through their corresponding factory methods fs.createWriteStream() and fs.createReadStream()) or by passing a file descriptor in options.

有一个问题需要尝试解决所有问题:Upgrade graphql-upload to 9.0 to support Node.JS 13 。关键是fs-capacitor已更新以解决此问题,但依赖于它的所有内容都需要相应更新。

目前,您需要使用 Node 12 或至少使用 13 之前的版本。

关于node.js - Docker 中 Apollo 服务器上传文件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58874406/

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