views:

110

answers:

1

Is anyone aware of any samples available for uploading a file using oAuth with DotNetOpenAuth and submitting via a multipart/form-data?

A: 

There is no sample of using it, but here is how you can use the PostMultiPart method, new in DotNetOpenAuth v3.3.

using DotNetOpenAuth.Messaging;

WebConsumer consumer; // you've initialized this
var endpoint = new MessageReceivingEndpoint(url, HttpDeliveryMethods.PostRequest | HttpDeliveryMethods. AuthorizationHeaderRequest);

IDirectWebRequestHandler requestHandler = consumer.Channel.WebRequestHandler;
var parts = new List<MultipartPostPart>();
parts.Add(MultipartPostPart.CreateFormPart("key", "value"));
parts.Add(MultipartPostPart.CreateFormFilePart("filefield", "c:\\temp\\foo.txt", "text/plain"));
HttpWebRequest req = consumer.PrepareAuthorizedRequest(endpoint, token);
IncomingWebResponse response = req.PostMultiPart(requestHandler, parts); // yes, it's an extension method
Andrew Arnott