How to attach audio recorded file in attachment?
Closed this issue · 1 comments
shorabhd commented
How to attach audio recorded file in attachment?
scottkawai commented
You'll want to retrieve the audio file as a Data
(formerly NSData
) instance. For instance:
do {
/// `filepath` is the URL to the location of your audio file.
let file = try Data(contentsOf: filepath)
} catch {
print(error)
}
Once you have the file represented as Data
, you can initiate a new Attachment
with that Data
as shown here.
do {
/// `filepath` is the URL to the location of your audio file.
let file = try Data(contentsOf: filepath)
let attachment = Attachment(
filename: "audio.mp3",
content: file,
disposition: .Attachment,
type: .other("audio/mpeg"),
contentID: nil
)
email.attachments = [attachment]
} catch {
print(error)
}