0

I have a Xamarin App, that I am using to create an Image and make an API call to Asp.net core which uploads it to Azure blob storage. However now I would like to save the image locally, to my external hard drive(using a Mac book) using Asp.net core web API. See below for my blob storage controller. Please help me modify it so I can save it locally (External hard-drive)

        public async Task<ActionResult> UploadFiles([FromForm]IFormFile file)
        {
            try
            {
                //foreach (var file in files)
                //{
                    var response = await _blobService.UploadBlobAsync(file.FileName, file, "containerName");
               // }

                return Ok(true);

            }
            catch (Exception ex)
            {
                return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error");
            }
        }```
Java_Dude
  • 97
  • 9
  • 1
    "local" to what? To the server running your ASP.NET service? Or local to the mobile app? To save it locally to the server, just use `File.WriteAllBytes` or a similar method to save it to a filepath. – Jason Mar 15 '22 at 19:29
  • To a hard drive C:// but in my case Volumes/ I'm on a Mac not sure how to do that though – Java_Dude Mar 15 '22 at 19:34
  • I just told you what to do. See https://learn.microsoft.com/en-us/dotnet/api/system.io.file?view=net-6.0#methods – Jason Mar 15 '22 at 19:36

1 Answers1

1

As we know, we can download the file from azure blob storage, and get Stream like below

Stream blobStream = blockBlob.OpenReadAsync().Result;

I think after we get the blobStream, then you need set file permission to 644, then you can save your file to specific folder.

Related Post:

Find your external path in MacOS

Jason Pan
  • 15,263
  • 1
  • 14
  • 29