carlosbm
carlosbm
CCConvex Community
Created by carlosbm on 1/21/2024 in #support-community
Upload Video from a RN Expo app to the Convex Storage
Hello! I'm having trouble saving a video from a RN Expo app to the Convex Storage. In the examples, there are only references to upload images. I'm trying to build a formData and doing several things, but I cannot get it working. I managed to upload the video to the Storage, and I see it uploaded with the proper size, but cannot change the name, nor I can play the video after downloading it because it is saved in a different extension. This is the code I have right now, if someone could help me would be great! Thanks!
const postUrl = await generateUploadUrl();

const form = new FormData();
form.append("video", {
uri,
type: "video/*",
name: "video.mp4",
});

// Step 2: POST the file to the URL
const result = await fetch(postUrl, {
method: "POST",
headers: { "Content-Type": "multipart/form-data" },
body: form,
});

const { storageId } = await result.json();
// Step 3: Save the newly allocated storage id to the database
await saveVideoStorageId({ videoStorageId: storageId });
const postUrl = await generateUploadUrl();

const form = new FormData();
form.append("video", {
uri,
type: "video/*",
name: "video.mp4",
});

// Step 2: POST the file to the URL
const result = await fetch(postUrl, {
method: "POST",
headers: { "Content-Type": "multipart/form-data" },
body: form,
});

const { storageId } = await result.json();
// Step 3: Save the newly allocated storage id to the database
await saveVideoStorageId({ videoStorageId: storageId });
7 replies