How to upload a file to Cloudflare?

Asked

Viewed 31 times

1

I want to upload a file to cloudflare, but before that, it uses protocol tus.

Follow the code below:

var cloudflare = new HttpClient();
var zoneId = "xxxxxxxxxxxxxxx";
var email = "[email protected]";
var key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var url = $"https://api.cloudflare.com/client/v4/zones/{zoneId}/media";

var fileinfo = new FileInfo(@"caminho do arquivo");

using (var request = new HttpRequestMessage(new HttpMethod("POST"), url))
{
    request.Headers.TryAddWithoutValidation("X-Auth-Email", email);
    request.Headers.TryAddWithoutValidation("X-Auth-Key", key);
    request.Headers.TryAddWithoutValidation("Tus-Resumable", "1.0.0");
    request.Headers.TryAddWithoutValidation("Upload-Length", fileinfo.Length.ToString());
    request.Content = new ByteArrayContent(File.ReadAllBytes(fileinfo.FullName));
    var response = await cloudflare.SendAsync(request);
}

The post of executing SendAsync(), returns code 201. So far so good.

But when it comes to listing all videos, it seems to me you didn’t. Follow the return code when listing videos:

{
    "result": [],
    "success": true,
    "errors": [],
    "messages": []
}

Why aren’t you saving file? What am I doing wrong ?

Follows the documentation Cloudflare.

Follows Curl api Cloudflare.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.