MCP Apps Kit - v0.5.0
    Preparing search index...

    Function useFileUpload

    • Hook for uploading files (ChatGPT only)

      Provides a function to upload files and tracks upload state. On unsupported platforms, isSupported will be false.

      Supported file types: PNG, JPEG, WebP images

      Returns UseFileUploadState & { upload: (file: File) => Promise<FileUploadResult> }

      Upload function and state

      function ImageUploader() {
      const { upload, isSupported, isUploading, error, fileId } = useFileUpload();

      if (!isSupported) {
      return <div>File upload not supported on this platform</div>;
      }

      const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
      const file = e.target.files?.[0];
      if (file) {
      const result = await upload(file);
      console.log("Uploaded:", result?.fileId);
      }
      };

      return (
      <div>
      <input type="file" accept="image/*" onChange={handleFileChange} />
      {isUploading && <span>Uploading...</span>}
      {error && <span>Error: {error.message}</span>}
      {fileId && <span>Uploaded: {fileId}</span>}
      </div>
      );
      }