Skip to main content
Participant
September 4, 2012
Question

File.CopyTo only works in same directory

  • September 4, 2012
  • 2 replies
  • 1004 views

When a user unpublishes a stream I want to take the recorded file and move it to a different location on our server.  I can only get the File.CopyTo to work when it's in the same directory and i'm not sure why; and the error thrown is useless.

The following code is the only copy I can get working.

application.onUnpublish = function (clientObj, streamObj) {

          var myFile = new File("streams/" + streamObj.name + "/" + streamObj.name + ".flv");

          if (myFile.copyTo("/streams/" + streamObj.name + "/" + streamObj.name + "meow.flv")) {

              trace("Copy completed");

          }

}

I've tried provided the full paths like C:\a\custom\dir but it never works.

Error I keep getting:

Sending error message: C:\Program Files\Adobe\Flash Media Server 4.5\applications\myapp\main.asc: line 77: Error: File operation copyTo failed.

code: Application.Script.Error level: error

Application.Script.Error details: C:\Program Files\Adobe\Flash Media Server 4.5\applications\myapp\main.asc: line 77: Error: File operation copyTo failed.  <-- Line 77 is myFile.copyTo(...)

This topic has been closed for replies.

2 replies

Zach_LAuthor
Participant
September 4, 2012

So I think it might be a permissions issue.

Inside my Application.xml I have the following VD

<FileObject>

                              <VirtualDirectory>/recorded;C:\Program Files\Adobe\Flash Media Server 4.5\applications\myapp\recorded</VirtualDirectory>

</FileObject>

And the following CopyTo works:

application.onUnpublish = function (clientObj, streamObj) {

          var myFile = new File("streams/" + streamObj.name + "/" + streamObj.name + ".flv");

 

          if (myFile.copyTo("/recorded/" + streamObj.name + ".flv")) {

              trace("Copy completed");

          }

}

But the second I try to copy to a folder outside of myapp, it fails.

October 22, 2012

Yes. This is my code that works. But I haven't tried to copy outside of the _defaultapplication_ directory.

application.onUnpublish = function(clientObj, streamObj)

{

        trace("onUnpublish : " + streamObj.name);

        trace("onUnpublish : " + clientObj.ip);

        var s = application.s[streamObj.name];

        if (s && s!= undefined)

        {

                s.record(false);

                s.play(false);

                s.liveEvent = "";

                application.s[streamObj.name] = null;

        }

        var fileObject = new File("streams/_definst_/"+streamObj.name+"/"+streamObj.name+"Seg1.f4f");

        {

                fileObject.copyTo("store/"+streamObj.name+".f4f")

        }

October 22, 2012

My next code delima is to check if the file already exists, and then to auto increment the filename with a integer, or add a timestamp to the file.

September 4, 2012

Thanks Zach_L for bringing this to light.. I've been working on this problem myself. I'd like to see this thread produce some results s owe can get content live streamed away for the applications directory after onUnpublish.