How can I attach an image to a post? #774
-
Hello, I'm thinking of using this package to create a post for Bluesky. How can I attach an image to a post with this? |
Beta Was this translation helpful? Give feedback.
Answered by
myConsciousness
Sep 12, 2023
Replies: 1 comment
-
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(
alt: 'My photo',
// Uploaded blob data.
image: uploaded.data.blob,
)
],
),
),
);
} Or you can do the same thing with: 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!',
// This is shortcut!
embed: uploaded.data.blob.toEmbedImage(
alt: 'My photo',
),
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @modalr8in ,
You can create a post from an image upload with the following implementation.