Back

Upload big file with SDK too many requests

  • 1
  • Web
  • Storage
WuGGu
25 Mar, 2024, 14:16

Hi all,

for a few month I use in my nuxt application the appwrite sdk to upload videos to my bucket. It worked like a charm but now I get too many requests errors. The only thing I changed is, I updated to Appwrite 1.5.3 I didn't test the video upload directly after I updated so it could be this change. I updated also the SDK to latest version "appwrite": "^14.0.0" but still get this too many requests error.

Any Idea how I can debug this?

btw: Uploading in the Appwrite Backend works perfectly fine.

TL;DR
Developers are experiencing too many requests errors when trying to upload a large file using an SDK after updating to Appwrite 1.5.3. The UploadVideoFile function is being utilized for the upload process. To debug the issue, check the compatibility between the current version of the Appwrite SDK and the specific upload process being used. Also, ensure that the backend upload in the Appwrite Backend is functioning correctly.
Guille
25 Mar, 2024, 14:21

Can you show your code?

WuGGu
25 Mar, 2024, 14:25

sure

TypeScript
  const uploadVideoFile = async (
    file: File,
    teamid: string | undefined,
    progress: (event: UploadProgress) => void,
  ) => {
    const { storage, ID } = useAppwrite();
    try {
      const permission = [];
      if (teamid) {
        permission.push(Permission.read(Role.team(teamid)));
        permission.push(Permission.write(Role.team(teamid, "owner")));
      }

      const res = await storage.createFile(
        VIDEO_BUCKET,
        ID.unique(),
        file,
        permission,
        progress,
      );
      return {
        success: true,
        data: res,
        error: null,
      };
    } catch (err) {
      if (err instanceof AppwriteException) {
        return {
          success: false,
          data: null,
          error: err.message,
        };
      } else {
        return {
          success: false,
          data: null,
          error: "Unkown Error",
        };
      }
    }
  };

my upload utils function. Component in the second post

WuGGu
25 Mar, 2024, 14:26
TypeScript
interface VideoFile {
  name: string;
  src: string; // Object URL for preview
  type: string; // MIME type of the video
  file: File; // The actual File object for upload
  size: number;
  duration: number | null;
  status: string;
}
const videos = ref<VideoFile[]>([]);

const onProgressFactory = (video: VideoFile) => {
  return (event: UploadProgress) => {
    video.status = `Uploading: ${Math.round(event.progress)}%`;
  };
};

const uploadAllFiles = async () => {
  for (const video of videos.value) {
    video.status = "Starting upload...";

    try {
      const fileUpload = await uploadVideoFile(
        video.file,
        editStore.teamID,
        onProgressFactory(video),
      );

      if (!fileUpload.success && fileUpload.error) {
        new Error(fileUpload.error);
      }
// creating a document in the db with the upload infos if success.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more