Very new to iOs development and Swift here!
I've been asked by a company I intern for to make an iOs app where the user records a few sentences-worth of audio, is able to listen back to said audio, and either re-record it or submit it. If they choose to submit it, the audio file is emailed to the company.
To accomplish this I've been using XCode 6.2 and Swift, using an iOs Simulator for testing.
So far I've accomplished everything but the "submit" part. I want to be able to temporarily upload the audio file to the company website server, and then send that file to the email address as an attachment using PHPMailer (please correct me if there's a better way). The problem is I can't seem to figure out how to upload the file.
In summary:
Step 1:
After recording, the audio file is saved on my simulated phone with the path:
file:///Users/macpro/Library/Developer/CoreSimulator/Devices/AEAF2794-1DBF-4C6C-B5D1-C7B039370D59/data/Containers/Data/Application/6CB9C44B-4961-446F-847A-C8F76FEB11B4/Documents/audiorecording.m4a
Step 2:
Use Swift to upload the audio file to the company's server (need help with this)
Step 3:
Use a PHPMailer script (something like below) to automatically email that file to a member of the company.
So can anyone just point me in the right direction for uploading an audio file to a server using Swift? From research, it looks like I should be using a library such as Alamofire or SwiftHTTP, but I'm yet to find a tutorial that explains sending an audio file (they all seem to be for images). Let me know if you have any advice!
Thanks.
I've been asked by a company I intern for to make an iOs app where the user records a few sentences-worth of audio, is able to listen back to said audio, and either re-record it or submit it. If they choose to submit it, the audio file is emailed to the company.
To accomplish this I've been using XCode 6.2 and Swift, using an iOs Simulator for testing.
So far I've accomplished everything but the "submit" part. I want to be able to temporarily upload the audio file to the company website server, and then send that file to the email address as an attachment using PHPMailer (please correct me if there's a better way). The problem is I can't seem to figure out how to upload the file.
In summary:
Step 1:
After recording, the audio file is saved on my simulated phone with the path:
file:///Users/macpro/Library/Developer/CoreSimulator/Devices/AEAF2794-1DBF-4C6C-B5D1-C7B039370D59/data/Containers/Data/Application/6CB9C44B-4961-446F-847A-C8F76FEB11B4/Documents/audiorecording.m4a
Step 2:
Use Swift to upload the audio file to the company's server (need help with this)
Step 3:
Use a PHPMailer script (something like below) to automatically email that file to a member of the company.
PHP:
<?php
if (!empty($_POST)) {
require '/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'MY MAIL HOST';
$mail->SMTPAuth = true;
$mail->Username = 'MY USERNAME';
$mail->Password = 'MY PASSWORD';
$mail->SMTPSecure = 'ssl';
$mail->SMTPKeepAlive = true;
$mail->Port = 465;
$mail->From = 'FROM ADDRESS';
$mail->FromName = 'FROM NAME';
$mail->addAddress("example@email.com");
$mail->isHTML(true);
$body = 'Here is your file';
$mail->AddAttachment(/uploads/audiorecording.m4a);
$mail->Subject = 'Uploaded audio';
$mail->Body = $body;
$mail->send();
}
So can anyone just point me in the right direction for uploading an audio file to a server using Swift? From research, it looks like I should be using a library such as Alamofire or SwiftHTTP, but I'm yet to find a tutorial that explains sending an audio file (they all seem to be for images). Let me know if you have any advice!
Thanks.
Last edited: