Web Dev Cody
Web Dev Cody3mo ago

youtube api in action

I'm trying to upload a file to youtube from a convex action, but I get this error:
Uncaught TypeError: part.body.pipe is not a function
at multipartUpload (../node_modules/googleapis-common/build/src/apirequest.js:180:12)
at createAPIRequestAsync (../node_modules/googleapis-common/build/src/apirequest.js:219:12)
at createAPIRequest (../node_modules/googleapis-common/build/src/apirequest.js:52:4)
at insert [as insert] (../node_modules/googleapis/build/src/apis/youtube/v3.js:2595:12)
at handler (../convex/youtube.ts:104:6)
Uncaught TypeError: part.body.pipe is not a function
at multipartUpload (../node_modules/googleapis-common/build/src/apirequest.js:180:12)
at createAPIRequestAsync (../node_modules/googleapis-common/build/src/apirequest.js:219:12)
at createAPIRequest (../node_modules/googleapis-common/build/src/apirequest.js:52:4)
at insert [as insert] (../node_modules/googleapis/build/src/apis/youtube/v3.js:2595:12)
at handler (../convex/youtube.ts:104:6)
const youtube = google.youtube({ version: "v3", auth: oauth2Client });
const fileStream = file.stream();
const fileSize = file.size;

await youtube.videos.insert(
{
part: ["snippet", "status"],
requestBody: {
snippet: {
title: video.title,
description: "this video was created using thevideocrafter.com",
},
status: {
privacyStatus: "private",
},
},
media: {
body: fileStream,
},
},
{
onUploadProgress: (evt) => {
const progress = (evt.bytesRead / fileSize) * 100;
console.log(`${progress.toFixed(2)}% complete`);
},
}
);
const youtube = google.youtube({ version: "v3", auth: oauth2Client });
const fileStream = file.stream();
const fileSize = file.size;

await youtube.videos.insert(
{
part: ["snippet", "status"],
requestBody: {
snippet: {
title: video.title,
description: "this video was created using thevideocrafter.com",
},
status: {
privacyStatus: "private",
},
},
media: {
body: fileStream,
},
},
{
onUploadProgress: (evt) => {
const progress = (evt.bytesRead / fileSize) * 100;
console.log(`${progress.toFixed(2)}% complete`);
},
}
);
3 Replies
Convex Bot
Convex Bot3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
lee
lee3mo ago
two clarifying questions: - is this a node action? - what is file? according to https://github.com/googleapis/google-api-nodejs-client/issues/1833 this error looks like what would happen if file.stream() has the wrong type
GitHub
part.body.pipe is not a function · Issue #1833 · googleapis/google-...
Environment details OS: Linux Node.js version: 12.9.0 npm version: 6.11.2 googleapis version: 43.0.0 Steps to reproduce I have the following piece of code: const drive = google.drive({ version: &#3...
Web Dev Cody
Web Dev CodyOP3mo ago
I fixed this by wrapping the convex file stream with a node stream
const fileStream = file.stream();

const nodeReadableStream = new Readable({
async read(size) {
const reader = fileStream.getReader();
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
this.push(null);
break;
}
this.push(Buffer.from(value));
}
} catch (error) {
this.destroy(error as Error);
} finally {
reader.releaseLock();
}
},
});
const fileStream = file.stream();

const nodeReadableStream = new Readable({
async read(size) {
const reader = fileStream.getReader();
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
this.push(null);
break;
}
this.push(Buffer.from(value));
}
} catch (error) {
this.destroy(error as Error);
} finally {
reader.releaseLock();
}
},
});

Did you find this page helpful?