I've got a .wav file on my machine. I want to upload that file (filename and file location never changes) to a url where REST is being used, but I'm having a really difficult time teasing out how this should be done. The request is supposed to make use of multi-part/form data. After uploading, the service will respond and I need to collect that data. I've got a hodgepodge of code and I just haven't made any progress.
From what I can tell a) I probably can't use upload with the POST method b) I might need to save my wav file as a bytearray, but I have no idea how to do that c) as is obvious, I'm fairly lost. Any help would be greatly appreciated.
Thanks,
Tap
Code:
function postFileAndRetrieveTranscript():void
{
var request:URLRequest = new URLRequest("my address here");
request.method = URLRequestMethod.POST;
request.contentType = 'multipart/form-data';
fileToPost = File.desktopDirectory.resolvePath("recording.wav");
fileToPost.addEventListener(Event.COMPLETE, completeHandler);
try
{
fileToPost.upload(request);
}
catch (error:Error)
{
trace("Unable to upload file.");
fileToPost.removeEventListener(Event.COMPLETE, completeHandler);
}
}
function completeHandler(event:Event):void
{
trace("uploaded");
var loader:URLLoader = URLLoader(event.target);
var transcript = new URLVariables(loader.data).success;
trace("transcript: " + transcript);
}