I have a NodeJS server set up on localhost (for testing) that I am using to run FFMPEG on video files that are uploaded. This is the actual node application I am uploading to. https://github.com/madebyhiro/codem-transcode The actual conversion process works correctly if I run a curl job in the OSX console using sudo curl -d '{"source_file": "MASTER.flv","destination_file":"converted.mp4","encoder_options": "-vcodec libx264 -vb 416k -s 320x180 -y -threads 0"}' http://localhost:8080/jobs
so I know the node server is running properly. You can see that a specific JSON object is required as part of the HTTP POST request. (In my AIR client code sample below this is the params Object which I have intentionally left blank.) On the client side I am using a AIR for desktop application to simply upload the video files. Many Questions - Is a primary issue simply that you cannot upload files on the same machine to a local server?
- Am I missing something from my requestHeaders?
- Should I be using contentType = "multipart/form-data" or some other contentType?
- Should contentType be part of the headers as I've done or defined as a property on the actual UrlRequest Object?
- Should I be using UrlLoader.load instead of File.upload?
- Is file.url formatted properly (assuming my str value is correct)?
- Any other errors or omissions in my uploadFile code method below?
Here is the relevant upload code. str is the nativePath to the actual video file I am uploading. As previously mentioned the JSON params Object has been intentionally left blank, so would need proper formatting for it to work properly. function uploadFile(str:String😞void { var params:Object={} var jsonOb:String = JSON.stringify(params); var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json"); var request:URLRequest=new URLRequest("http://localhost:8080"); request.requestHeaders.push(hdr); request.method=URLRequestMethod.POST; request.useCache=false; request.cacheResponse=false; //pass urlVariables instead of JSON Object?? request.data=jsonOb;
var file:File=new File(); configureListeners(file); file.url='file:///'+str;
try { file.upload(request); } catch (e:Error) { trace('error', e); }
}
private function configureListeners(dispatcher:IEventDispatcher😞void { dispatcher.addEventListener(ProgressEvent.PROGRESS, uploadProgressHandler, false, 0, false); dispatcher.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpResponseHandler, false, 0, false); dispatcher.addEventListener(Event.COMPLETE, uploadCompleteHandler, false, 0, true); dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler, false, 0, true); dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false, 0, true); dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true); }
|