Force.com-Toolkit-for-NET icon indicating copy to clipboard operation
Force.com-Toolkit-for-NET copied to clipboard

Content-Type error on PostFeedItemWithAttachmentAsync

Open busbina opened this issue 4 years ago • 0 comments

I am getting the following error:

ForceException: Binary data included but file attachment information is missing. If providing rich JSON/XML input in multipart REST, make sure to include Content-Type header in the part.

when I call PostFeedItemWithAttachmentAsync.

Here is my code:

        var instanceUrl = auth.InstanceUrl;
        var accessToken = auth.AccessToken;
        var apiVersion = auth.ApiVersion;
        var chatter = new ChatterClient(instanceUrl, accessToken, apiVersion);
        var me = chatter.MeAsync<UserDetail>().Result;
        var input = new ObjectFeedItemInput();
        input.ObjectId = me.id;

        var memoryStream = new MemoryStream();
        stream.CopyTo(memoryStream);
        var bytes = memoryStream.ToArray();

        var result = await chatter.PostFeedItemWithAttachmentAsync<FeedItem>(input, bytes, "319051.jpg");

I turned on the system.net diagnostics and can see these headers in my logs.

Content-Type: application/octet-stream Content-Disposition: form-data; name="feedElementFileUpload"; filename="319051.jpg"

busbina avatar Jul 24 '20 04:07 busbina