0

The minimal API was written as below. How can I write a client (something like a proxy) to download the file and then forward the content to another WebAPI server?

app.MapGet("/myapi", () =>
{
    FileStream fs = File.OpenRead("my.jpg");
    return Results.File(fs, "image/jpeg", "my.jpg");
});
s k
  • 4,342
  • 3
  • 42
  • 61

1 Answers1

0

You may try as below with restsharp:

using var client1 = new RestClient("uri1");
var request = new RestRequest("myapi", Method.Get);
byte[] response = client1.DownloadData(request);

using var client2 = new RestClient("uri2");
var uploadRequest = new RestRequest("upload",Method.Post);
uploadRequest.AddFile("file",  response, "mypic", "image/jpeg");
uploadRequest.AddHeader("Content-Type", "multipart/form-data");
var attachmentResponse = client2.Execute(uploadRequest);
//check if success
var success = attachmentResponse.IsSuccessful;

Result:

enter image description here

Ruikai Feng
  • 6,823
  • 1
  • 2
  • 11