Tim Kathete Stadler
Tim Kathete Stadler

Reputation: 1069

Upload local image to deviantsart

I am trying to upload an image to http://deviantsart.com On the website it states:

Upload using our public REST API: POST http://deviantsart.com yourimage.jpg

I am trying to do this in C# like this:

    using (var client = new HttpClient())
    {
        var values = new Dictionary<string, string>
        {
            { "file", @"@C:\Users\bla\Desktop\gr.PNG" },
        };

        var content = new FormUrlEncodedContent(values);

        var response = await client.PostAsync("http://deviantsart.com/upload.php", content);

        var responseString = await response.Content.ReadAsStringAsync();
    }

But I am just getting the raw html from the site as a response. What am I doing wrong?

Upvotes: 0

Views: 42

Answers (1)

Clint
Clint

Reputation: 6220

You're not actually trying to upload the file, instead you're just trying to send them the path to the file on disk.

I'd recommend using something like RestSharp which should make uploading the file much easier.

var client = new RestClient("http://deviantsart.com");
var request = new RestRequest("upload.php", Method.POST);
request.AddFile("pathtofileondisk.jpg");

var response = client.Execute(request);

Upvotes: 1

Related Questions