0

Hello im trying upload file to a link and i tried this:

`private void buttonInput_Click(object sender, EventArgs e)
    {
        try
        {
            using (WebClient client = new WebClient())
            {
                var resStr = client.UploadFile(@"https://anonfiles.com", @"C:\Users\sadettin\desktop\test.txt");
                var jObjResult = JObject.Parse(Encoding.UTF8.GetString(resStr));
                var linkToFile = jObjResult["link"];
            }
        }
        catch(Exception err)
        {
            MessageBox.Show(err.Message);
        }
    }`

But Im taking 404 error.

Now i want to send any txt file to my discord webhook address and take sent file's link.

How can i do?

  • You need to post to a different end-point, according to the specs: https://anonfiles.com/docs/api did you try `https://api.anonfiles.com/upload` as the address? – rene Apr 02 '22 at 15:43
  • @rene Hello i changed address to https://api.anonfiles.com/upload but im taking same error. – NoobCoder31 Apr 02 '22 at 15:48

1 Answers1

0

Despite your claims, using the correct end-point and a non-zero bytes file does lead to an uploaded file:

using (WebClient client = new WebClient())
{
      var resStr = client.UploadFile(@"https://api.anonfiles.com/upload", @"C:\tmp\test.txt");
      var jObjResult = JObject.Parse(Encoding.UTF8.GetString(resStr));
      var linkToFile = jObjResult["data"]["file"]["url"]["full"].ToString();
      MessageBox.Show(linkToFile);
}

Do note that the JSON structure that is returned is different then you seem to handle. The url is found in an attribute full under this path /data/file/url hence this line in my code example:

var linkToFile = jObjResult["data"]["file"]["url"]["full"];

Here is one of the full urls that the service returned to me with my test file

https://anonfiles.com/nai0Z3S0x5/test_txt

It is 106 bytes in total.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
rene
  • 41,474
  • 78
  • 114
  • 152
  • Hello I edited code with this and im taking: "The remote server returned an error: (400) bad request." error – NoobCoder31 Apr 02 '22 at 16:25
  • Hello i fixed it. Problem is: my txt file is 0 byte i just randomamly wrote somethings inside txt file and tested it again and works but i have a question how i can display it in MessageBox? I would be very happy if you help. – NoobCoder31 Apr 02 '22 at 18:01
  • @NoobCoder31 you were able to show the exception. Showing the link is similar, see my updated snippet. – rene Apr 02 '22 at 18:53
  • I tried it before and im taking this error: "Error CS1503 1 argument: Cannot convert from 'Newtonsoft.Json.Linq.JToken' to 'string'" – NoobCoder31 Apr 02 '22 at 18:59
  • @NoobCoder31 just add a ToString call as shown in my snippet now – rene Apr 02 '22 at 19:18