Method CreateFromBase64String
CreateFromBase64String(string, string)
Creates a new Attachment instance from a base64-encoded string.
public static Attachment CreateFromBase64String(string s, string name)
Parameters
s
stringA string containing the base64-encoded representation of the attachment's content.
name
stringA string specifying the name of the attachment file. This name is used to identify the file and determine its MIME type based on the content.
Returns
- Attachment
A new instance of the Attachment class initialized with the decoded content and the specified name.
Remarks
This method is particularly useful when the attachment data is received in a base64-encoded format, such as when transmitted over text-based protocols or embedded within JSON or XML payloads. It ensures that the data is properly decoded and validated against supported image formats before creating the attachment object.
Exceptions
- ArgumentNullException
Thrown if either
s
orname
isnull
.- FormatException
Thrown if the provided string
s
is not a valid base64 string.- UnsupportedFileTypeException
Thrown if the decoded content does not correspond to one of the supported image formats:
- PNG
- BMP
- GIF
- PSD
- PIC
- JPEG
- PNM
- HDR
- TGA