node.js - 在 Nodejs 中将视频上传到 GCP 云存储
问题描述
我正在尝试将视频从我的颤振客户端上传到我的节点 API。我将来自客户端的文件作为流发送,我的服务器将其作为application/octet-stream
.
如何在我的服务器上将八位字节流转换为 .mp4 格式?
当我刚刚multipart/form-data
上传时,以 .mp4 格式上传到 GCP 存储没有问题。但是由于视频会很快变大,所以我想将其分块发送到我的 API。
这是我当前的实现:
const newFileName = 'newFile';
const bucket = storage.bucket('dev.appspot.com');
const blob = bucket.file(newFileName);
const blobStream = blob.createWriteStream({
contentType: 'video/mp4',
metadata: {
contentType: 'video/mp4',
},
});
blobStream.on('error', (err) => console.log(err));
blobStream.on('finish', () => {
console.log('finished');
});
req.pipe(blobStream);
req.on('end', () => {
console.log('upload complete');
});
更新/修订
req.pipe(blobStream);
没有工作,因为我将整个请求正文通过管道传输到导致问题的 CGS 中。
我现在有
const newFileName = 'newFile';
const bucket = storage.bucket('dev.appspot.com/postVideos');
const blob = bucket.file(newFileName);
const blobStream = blob.createWriteStream({
metadata: { contentType: 'video/mp4' },
});
blobStream.on('error', (err) => {
reject(err);
});
blobStream.on('finish', () => {
resolve();
});
req.on('data', function(chunks) {
// this is recieving video from the client in buffer chunks, but I have not figured out how to pipe those chunks into GCS as one file
})
现在我正在从客户端接收缓冲区块,我仍然无法弄清楚如何将这些块流式传输到 GCS 以获取一个连续的文件上传。
解决方案
推荐阅读
- r - 当我添加任何东西时,ggplot映射aes错误
- javascript - Nuxt 和 cloudinary - 将图像从客户端直接上传到 cloudinary
- javascript - 下载的文件与服务器上的文件不同
- r - 内连接 - 在 R 中分配向量
- c++ - Eigen 中立方根的性能改进
- informatica - 如何连接多个表并将某个列(在具有不同值的所有表中重复)放入具有一列的单个目标表中
- python - Pytorch:掩码膨胀/扩展
- php - 尝试将 Laravel 从版本 6 升级到 7 时出现问题
- asp.net-core - 激活服务工作者时重新发送请求
- javascript - 如何使丰富的嵌入使用用户的显示颜色 discord.js