1

I have an API with a specific endpoint used by some applications to send images.

[HttpPost("dropimage")]
public string UploadImage([FromForm] IFormFile file)
{
    try
    {
        string FileName = file.FileName;
        string uniqueFileName = Guid.NewGuid().ToString() + "_" + FileName;
        var imagePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", FileName);

        file.CopyTo(new FileStream(imagePath, FileMode.Create));

        return "Successful";
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
}

This is working fine and files are correctly received within wwroot/images folder.

Note: this .NET Core 7 app is deployed on Debian 10 (dotnet7.0.102 actually)

My question

I want to copy the file, once received, to another file server (Rhel server 7.9).

As servers used are Linux based, I thought I could use a mount point to do so (it should work), but is there any possibility to do it programmatically (in case I have a Windows server)?

I saw some posts (this one or this one) about this subject, unsuccessful yet.

Can someone please point me in the right direction ?

Regards,

Pierre

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tanc
  • 87
  • 1
  • 10

1 Answers1

1

All I could understand from your question is that you can download the file using UploadImage, but you need the capability to store your file in Linux and Windows both.

As shown here: At first you can use Mountpoint: Using A Mountpoint

And then you can use Path.DirectorySeparatorChar Or Path.Combine.

Both Path.DirectorySeparatorChar and Path.Combine should help you deal with file paths in Windows and Linux file systems. Path.DirectorySeparatorChar will help you enter the DirectorySeparatorChar of choice i.e. '/' or '\'. The Path.Combine can concatenate individual strings into a single string that represents a file path.

R_V
  • 41
  • 8