一个 ios 应用程序调用一个 .net 核心 Web API(post 方法)来发送一些详细信息以保存在 SQL 数据库中。我必须将此图像保存在一个 blob 中并将其命名为 EmpID_PunchInDate_PunchInTime.png
我有下面的代码,但我无法弄清楚如何在 post 方法中调用 post 方法
/// <summary>
/// The PostPunchInDetailsToAzure
/// </summary>
/// <param name="item">The item<see cref="Punch_In"/></param>
/// <returns>The <see cref="Task{IActionResult}"/></returns>
[HttpPost]
[Route("PostPunchInDetailsToAzure")]
// POST: api/PunchIn/PostPunchInDetailsToAzure
public async Task<IActionResult> PostPunchInDetailsToAzure([FromBody] Punch_In item)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var srtBase64Encoded = item.ClockInNotesForSelfie;
string fullOutputPath = "E:\\temp\\img.png";
byte[] imageBytes = Convert.FromBase64String(srtBase64Encoded);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Write(imageBytes, 0, imageBytes.Length);
ms.Position = 0;
System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
System.Drawing.Image img = Base64ToImage(srtBase64Encoded);
img.Save(fullOutputPath, System.Drawing.Imaging.ImageFormat.Png);
var stream = img.ToStream(ImageFormat.Png);
_context.Punch_Ins.Add(item);
await _context.SaveChangesAsync();
return Ok(new { result = "Data stored succesfully." });
}
传入的请求以 JSON 的形式出现,如下所示(例如)
{
"ClockInEmpId":"1000",
"clockInDate":"10/23/2019",
"ClockInTime":"13:23",
"clockInLatitude":"12.919456",
"clockInLongitude":"77.649802",
"clockInLaborAccountName":"/@H///@H//620108",
"ClockInHQTravelTime":"00:00",
"clockInPerDiem":"00.00",
"clockInNotes":"Hello",
"ClockInNotesForSelfie":"A Base 64 string"
}
因此,图像应保存为 1000_10232019_1323.png 在 Azure Blob 中,并应返回 Blob URL。我怎样才能做到这一点?