gave92 / fbchat-sharp

Facebook Messenger client library for C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[QUESTION] How to sendLocalFiles?

apepenkov opened this issue · comments

Stream stream = new MemoryStream(File.ReadAllBytes(@attachment));
var dct = new Dictionary<string, Stream>();
dct.Add(attachment, stream); 
msg_uid = await client.sendLocalFiles(dct, message, user, ThreadType.USER);

Is wrong, because throws errors.

fbchat_sharp.API.FBchatException
Error: Message: Some files could not be uploaded: {
  "uploadID": null,
  "metadata": []
}

attachment is a full path to file

Hello the following works for me, both from netcore and WPF app.

// Send a local image to myself
using (FileStream stream = File.OpenRead(@"C:\Users\BLABLA\test_image.jpg"))
{
    await Client.sendLocalImage(@"C:\Users\BLABLA\test_image.jpg", stream, null, Client.GetUserUid(), ThreadType.USER);
}

that's localImage, i need any file

and it throws

Error: Message: Some files could not be uploaded: {
  "uploadID": null,
  "metadata": []
}

I can send a pdf with the following. What kind of file are you trying to send?

using (FileStream stream = File.OpenRead(@"C:\Users\PATH\a032.pdf"))
{
    await client.sendLocalFiles(
        file_paths: new Dictionary<string, Stream>() { { @"C:\Users\PATH\a032.pdf", stream } },
        message: null,
        thread_id: client.GetUserUid(),
        thread_type: ThreadType.USER);
}

thanks