Skip to content

How can I attach an image to a post? #774

Answered by myConsciousness
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @modalr8in ,

You can create a post from an image upload with the following implementation.

import 'dart:io';

import 'package:bluesky/bluesky.dart' as bsky;

Future<void> main() async {
  // Authentication is required.
  final session = await bsky.createSession(
    identifier: 'handle or email',
    password: 'password',
  );

  final bluesky = bsky.Bluesky.fromSession(session.data);

  final uploaded = await bluesky.repositories.uploadBlob(
    File('photo.png').readAsBytesSync(),
  );

  await bluesky.feeds.createPost(
    text: 'This is my photo!',

    // Set embed parameter.
    embed: bsky.Embed.images(
      data: bsky.EmbedImages(
        images: [
          bsky.Image(
      …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant