edproton
edproton4w ago

I'm trying to upload data but it says Property 'store' does not exist on type 'StorageWriter'

How can I upload stuff? I'm reading this https://docs.convex.dev/file-storage/store-files but the .store does not exists "convex": "^1.17.2",
export const seedTutors = internalMutation({
handler: async (ctx) => {
const data: TutorProfileJSON[] = JSON.parse(seedTutorsData);
const hasData = await ctx.db.query("tutors").take(1);
if (hasData.length > 0) {
console.log("Data already seeded");
return;
}

for (const row of data) {
if (
row.profileImageUrl.endsWith(".svg") ||
row.profileImageUrl.includes("placeholder")
) {
continue;
}

const response = await fetch(row.profileImageUrl);
const image = await response.blob();

const storageId = await ctx.storage.store(image);

const userId = await ctx.db.insert("users", {
name: row.name,
email: `${row.name.toLowerCase().replace(" ", ".")}@mtxceltutors.com`,
emailVerificationTime: Date.now(),
});

const tutorId = await ctx.db.insert("tutors", {
user: userId,
tags: row.tags,
bio: {
main: row.bio,
session: row.sessionBio,
short: row.bioShort,
},
});
}
},
});
export const seedTutors = internalMutation({
handler: async (ctx) => {
const data: TutorProfileJSON[] = JSON.parse(seedTutorsData);
const hasData = await ctx.db.query("tutors").take(1);
if (hasData.length > 0) {
console.log("Data already seeded");
return;
}

for (const row of data) {
if (
row.profileImageUrl.endsWith(".svg") ||
row.profileImageUrl.includes("placeholder")
) {
continue;
}

const response = await fetch(row.profileImageUrl);
const image = await response.blob();

const storageId = await ctx.storage.store(image);

const userId = await ctx.db.insert("users", {
name: row.name,
email: `${row.name.toLowerCase().replace(" ", ".")}@mtxceltutors.com`,
emailVerificationTime: Date.now(),
});

const tutorId = await ctx.db.insert("tutors", {
user: userId,
tags: row.tags,
bio: {
main: row.bio,
session: row.sessionBio,
short: row.bioShort,
},
});
}
},
});
Storing Generated Files | Convex Developer Hub
Files can be uploaded to Convex from a client and stored directly, see
9 Replies
Convex Bot
Convex Bot4w 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!
jamwt
jamwt4w ago
your function is a mutation; you need to store data in storage in an action
jamwt
jamwt4w ago
Storing Generated Files | Convex Developer Hub
Files can be uploaded to Convex from a client and stored directly, see
jamwt
jamwt4w ago
the example uses a separate mutation to commit the storage id etc to the database after the blob is uploaded into convex storage that's the right way to do it
jamwt
jamwt4w ago
why are these different? if you need to have "effects" -- use the network, do things that can fail half way through -- you have to use actions for that. a bit of background on that is in the tutorial, like here: https://docs.convex.dev/tutorial/actions
3: The platform in action | Convex Developer Hub
Learn about harnessing the broader backend platform capabilities to
edproton
edprotonOP4w ago
Thanks, that helped me understand the problem. Outside world * Actions Internal world (convex stuff) * Mutations What's the big difference between them? Am I right?
jamwt
jamwt4w ago
yes, mutations are very fast, side-effect free functions that run "in the database", and can only affect the database. actions are more like normal javascript functions that can run for longer, call APIs, etc, conduct multiple database queries/mutations, etc.
edproton
edprotonOP4w ago
Thanks a lot Jamie
jamwt
jamwt4w ago
no problem. happy to help

Did you find this page helpful?