I have an ASP.NET CORE API app and now I have an endpoint like:

[SwaggerResponse(200, typeof(string))]
[SwaggerResponse(400, typeof(string))]
public async Task<IActionResult> SendReceipt([FromBody] EmailDetails emailDetails)
        var requestId = HttpContext.TraceIdentifier;
        var connectionId = HttpContext.Features.Get<IHttpConnectionFeature>().ConnectionId;
        await _emailSender.SendEmailAsync(emailDetails, requestId, connectionId);
        return Ok($"The mail has been sent successfully.");
    catch (Exception ex)
        return BadRequest($"Error sending email: {ex.Message}");

While Model looks like:

public class EmailDetails
    [EmailAddress(ErrorMessage = "Invalid Email Address")]
    public string Email { get; set; }

    public string Subject { get; set; }

    public string Receipt { get; set; }

So for now as you can see I'm getting an image in Base64 encoded string and then I convert it to the image.

Is it a good idea to get an image in that way? Maybe should I use some alternative solution?

If you need any assistance, please let me know.

  • \$\begingroup\$ Is your code working and sending images as expected? \$\endgroup\$ – t3chb0t May 10 '17 at 8:08
  • 1
    \$\begingroup\$ Yes, it works fine. I'm asking if is a good solution? \$\endgroup\$ – cactodevcie May 10 '17 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.