Quantcast
Channel: Adobe Community : Unanswered Discussions - AIR Development
Viewing all articles
Browse latest Browse all 2010

URL request and uploading video file to NodeJS server

$
0
0

I've asked this on stackoverflow and am pulling my hairout! Any tips suggestions welcome!

 

json - AIR, URLRequest and uploading video file to NodeJS server - Stack Overflow

 

 

 

 

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

  1. Is a primary issue simply that you cannot upload files on the same machine to a local server?
  2. Am I missing something from my requestHeaders?
  3. Should I be using contentType = "multipart/form-data" or some other contentType?
  4. Should contentType be part of the headers as I've done or defined as a property on the actual UrlRequest Object?
  5. Should I be using UrlLoader.load instead of File.upload?
  6. Is file.url formatted properly (assuming my str value is correct)?
  7. 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=newURLRequestHeader("Content-type","application/json");
  
var request:URLRequest=newURLRequest("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=newFile();
  configureListeners
(file);
  file
.url='file:///'+str;

  
try{
  file
.upload(request);
  
}catch(e:Error){
  trace
('error', e);
  
}

  
}

  
privatefunction 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);
  
}


Viewing all articles
Browse latest Browse all 2010

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>