React Api Reference
    Preparing search index...

    Class useFile

    useFile provides methods to upload files to and retrieve files from VideoSDK’s temporary file storage.

    Index

    Constructors

    Methods

      • This method can be used to retrieve a previously uploaded file from VideoSDK's temporary storage.
      • The returned value is a Base64-encoded string.

      Parameters

      • options: { token: string; url: string }
        • token: string

          VideoSDK authentication token.

        • url: string

          The file URL returned by uploadBase64File().

      Returns Promise<string>

      A Base64-encoded string of the requested file.

      const { fetchBase64File } = useFile();

      async function fetchFile() {
      const url = "<FILE_URL>";
      const token = "<VIDEOSDK_TOKEN>";

      const base64 = await fetchBase64File({ url, token });
      console.log("base64:", base64);
      }
      • This method can be used to upload a file to VideoSDK's temporary storage.
      • This method returns a fileUrl, which can later be used to retrieve the uploaded file.

      Parameters

      • options: { base64Data: string; fileName: string; token: string }
        • base64Data: string

          Base64-encoded representation of the file.

        • fileName: string

          Name of the file including its extension.

        • token: string

          VideoSDK authentication token. Learn more about tokens here.

      Returns Promise<string>

      const { uploadBase64File } = useFile();

      async function uploadFile() {
      const base64Data = "<YOUR_FILE_BASE64_DATA>";
      const token = "<VIDEOSDK_TOKEN>";
      const fileName = "myImage.jpeg";

      const url = await uploadBase64File({
      base64Data,
      token,
      fileName,
      });

      console.log("fileUrl:", url);
      }