Highlighted

URL request and uploading video file to NodeJS server

Community Beginner ,
Jan 30, 2015

Copy link to clipboard

Copied

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

TOPICS
Development

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

URL request and uploading video file to NodeJS server

Community Beginner ,
Jan 30, 2015

Copy link to clipboard

Copied

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

TOPICS
Development

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 30, 2015 0

Have something to add?

Join the conversation