Native sharing

Open the device's native share sheet to share text, images, video, files, or an Instagram Story.

Open the share sheet

Examples reuse the single browser client from Set up the client. Adjust the ~/lib/bdk import to your app’s path; do not create a client in each component or handler.

Hand content to the device's native share sheet so the user can send it to another app like Messages, Mail, or Instagram. There is no result event — the call resolves once the sheet is requested, not when the user completes or cancels the share.

When not running in the app, the call doesn't run — triggered is false (pending in a browser tab, skipped with no window).

import { bdk } from "~/lib/bdk";

// Each method dispatches and forgets — await confirms the sheet was requested.
await bdk.share.text({ text_content: "Check out this app!" });

Share text

Share a string of text. The only field is text_content — to share a link, include the URL in the text. Use it for "Share this link" and "Tell a friend" flows.

import { bdk } from "~/lib/bdk";

await bdk.share.text({ text_content: "Check out this app! https://example.com" });

Share an image

Share a hosted image by URL. Pass a bare string, not an object.

Wrap the call in try/catch and keep another share option available if it fails. Do not let an optional share failure stop unrelated work.

A protocol-relative URL beginning with // is upgraded to https://.

The examples use your app’s showActionUnavailable() UI handler.

import { bdk } from "~/lib/bdk";

try {
  await bdk.share.image("https://example.com/photos/sunset.jpg");
} catch {
  showActionUnavailable();
}

Share a video

Share a video by URL. Pass a bare string.

Wrap the call in try/catch and keep another share option available if it fails. Do not let an optional share failure stop unrelated work.

The examples use your app’s showActionUnavailable() UI handler.

import { bdk } from "~/lib/bdk";

try {
  await bdk.share.video("https://example.com/clips/demo.mp4");
} catch {
  showActionUnavailable();
}

Share a file

Share any file by URL — a PDF, a document, a download. Pass a bare string.

Wrap the call in try/catch and keep another share option available if it fails. Do not let an optional share failure stop unrelated work.

The examples use your app’s showActionUnavailable() UI handler.

import { bdk } from "~/lib/bdk";

try {
  await bdk.share.file("https://example.com/docs/invoice.pdf");
} catch {
  showActionUnavailable();
}

Share to an Instagram Story

Open content directly in the Instagram Stories composer for a one-tap "Share to your Story" button.

Do not read server-only environment variables from browser code. Supply public application configuration through your build tool and keep secrets on the server.

Wrap the call in try/catch and keep another share option available if it fails. Do not let an optional share failure stop unrelated work.

The examples use your app’s showActionUnavailable() UI handler.

import { bdk } from "~/lib/bdk";

try {
  await bdk.share.instagramStory({
    app_id: "your-instagram-app-id",
    background_image_url: "https://example.com/story-bg.jpg",
    sticker_url: "https://example.com/sticker.png"
  });
} catch {
  showActionUnavailable();
}

Check the result

Each method resolves a NativeCommandResult. Inspect triggered to confirm the share sheet opened — there is no event reporting whether the user finished the share.

The examples use your app’s showActionUnavailable() UI handler.

import { bdk } from "~/lib/bdk";

try {
  const result = await bdk.share.image("https://example.com/photo.jpg");
  console.log(result.command);   // "shareImage"
  console.log(result.triggered); // true if it reached the app

  if (!result.triggered) {
    console.log("Share unavailable:", result.reason);
  }
} catch {
  showActionUnavailable();
}

Share a list of files

Share one or more file URLs. share.files is sugar for share.send with only urls.

const result = await bdk.share.files(
  ["https://app.example.com/api/report.pdf"],
  { title: "Share report" }
);

if (!result.ok) {
  console.log(result.code, result.message);
  return;
}

console.log(result.outcome, result.items.shared);

See it running in the live demo, or every native feature with its demo on thebdk.com.