Sending files via HTTP to web service

iosweb services

I am bit frustrated at the lack of information about this online. Here is the issue:

I am in charge of creating a iOS application which sends sound data back and forth between the server and the app. The Audio is in small files and thus does not need to be streamed over, but rather it can be sent. Right now, I am using a TCP server I wrote to handle applications like this. However, I want to keep the system as simple as possible and writing your own server and client sockets can get a bit complex and leaves room for crashes. Overall it slows down development because I need to account for packet structure and other things.

My question is, can I write an ASPX or PHP web service that lets me pass the files back and forth through GET or POST?

Best Answer

Where are you searching for information and not finding it? Uploading a file to a PHP webpage is a topic that has been covered quite a few times on the web over the years. So much so that even w3schools has a example.

From the client side (HTML example but it is just a basic HTTP POST):

<form action="http://example/com/upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file" id="file" /> 
    <input type="submit" name="submit" value="Submit" />
</form>

The server side of things in PHP:

<?php
    if ($_FILES["file"]["error"] > 0) {
        echo "Error: " . $_FILES["file"]["error"] . "<br />";
    } else {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
?>

As far as sending the files back to the client simply store the in a web assecible location and it is a basic GET request:

GET http://example.com/myfile.wav
Related Topic