我正在尝试上传多个图像以供Apollo服务器使用
我成功使用createWriteStream模块将流转换为文件
但是我不需要make文件,只需要缓冲字符串
但这永远不会返回永远不会缓冲的字符串
请参阅我的代码
type Mutation {
createProduct(product_name: String!, product_info: String!, price: Int!, sale: Int, files: [Upload!]): Result!
}
这是我的变异
createProduct(parent, {product_name, product_info, price, sale ,files }) {
db.Product.create({
product_name, product_info, price, sale
}).then( (product) => {
storeImages(files, product.id)
.then ( (result) => {
console.log(result)
})
})
这是我的解析器
const outStream = new Writable({
write(chunk, encoding, callback){
console.log(chunk)
},
})
const inStream = new Readable({
read(size) {
console.log(size)
}
})
const test2 = (chunk) => {
console.log(chunk)
outStream.destroy();
}
function test(){
let pass = new PassThrough();
console.log(pass)
console.log('pass!!')
return 'end';
}
const processUpload = async upload => {
const { stream, filename, mimetype } = await upload;
console.log('stream')
console.log(upload)
// const { id, path } = await storeFS({ stream, filename })
// return storeDB({ id, filename, mimetype, path })
}
const lastStream = (chunk) => {
console.log(chunk)
}
const storeImages = (files, product_id) => {
return new Promise( async (resolve, reject) => {
let save = []
files.forEach( async (image, index) => {
const { stream } = await image;
stream
.pipe(outStream)
// .pipe(inStream)
})
resolve(save)
最后,我尝试过的方式
我总结一下。
如何使用apollo上传服务器将多个文件流导入Blob并进行控制?