wadewegner / Force.com-Toolkit-for-NET

The Force.com Toolkits for .NET provides an easy way for .NET developers to interact with the Force.com & Chatter REST APIs using native libraries.
BSD 3-Clause "New" or "Revised" License
374 stars 396 forks source link

Content-Type error on PostFeedItemWithAttachmentAsync #382

Open busbina opened 4 years ago

busbina commented 4 years ago

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"