public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Vendor File In triggered. Attemping upload of file from body of API call..."); // Create blob operator working on in-blob CommonBlob blobOps = new CommonBlob("in"); // Store binary file from request body as stream Stream data = req.Body; // Create unique file name as combo of datetime and Guid DateTime _date = DateTime.Now; var _dateString = _date.ToString("dd-MM-yyyy"); string fileId = Guid.NewGuid().ToString(); string fileName = $"{_dateString}-{fileId}.xlsx"; // Address where blob can be found at Uri retUri = await blobOps.uploadFileToBlob(data, fileName); Console.WriteLine(retUri.AbsoluteUri); // Return id of file in blob var blobname = $"{_dateString}-{fileId}"; return(new OkObjectResult(new { fileId = fileName })); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# Blob to File Function processed a request."); // Get id and path from query parameters string id = req.Query["id"]; string path = req.Query["path"]; // Set default in case no parameters are given (only works for me!) if (id == ".xlsx") { // No id in parameter should return blank file. id = "download.xlsx"; } if (path == null) { // Automatically sets download path to Downloads //path = new KnownFolder(KnownFolderType.Downloads).Path+"\\"; } // Create blob operator working on 'out' blob CommonBlob blobOps = new CommonBlob("out"); // Bring container instance into this scope CloudBlobContainer cloudBlobContainer = blobOps.getLocalCloudBlobContainer(); // Pull blob with given id from container. If none match, null is returned CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(id); // Frodes method of returning a binary stream if (path == null) { log.LogInformation("Returning file as binary stream to API client"); await blobOps.getListAsStream(id); } // Download file directly from blob to API client machine await cloudBlockBlob.DownloadToFileAsync($"{path}{id}", FileMode.Create); // Return destination file was downloaded to return(new OkObjectResult($"File downloaded. Can be found at path: {path}{id}")); }