actionscript 3 - as3 selecting a file dynamically -


i need select video file , convert byte array. file trying select has been recorded cameraui interface. can path file using

filename = media.file.url; readfileintobytearray(filepath, inbytes); 

when passing byte array need select directory first , pass in the rest of path.

private function readfileintobytearray(filename:string, data:bytearray):void  {      var infile:file = file.userdirectory;     infile = infile.resolvepath(filename);      trace (infile.url);     instream.open(infile , filemode.read);     instream.readbytes(data);  } 

this leads duplication of first part of path. want keep dynamic run on different devices. hard coded file the variables section of flash debugger , worked error if leave out file.userdirectory

thanks in advance appreciated

you should use file.applicationstoragedirectory instead of file.userdirectory. due security risk vary vary different device. file.applicationstoragedirectory work device.

robust way of working filepath

var firstpartpath:string = file.applicationstoragedirectory.nativepath; var fullpath:string = file.applicationstoragedirectory.resolvepath("filename.jpg").nativepath; var expectedpath:string = fullpath.replace(firstpartpath,""); // "/filename.jpg" 

here expectedpath value should pass around project instead of hard code value c:\users\xxxx\ , save database use expectedpath value.

for latter access file pass expectedpath.

var infile:file = file.applicationstoragedirectory.resolvepath(expectedpath); 

needn't worry forward , backword slashes. file resolvepath() take care you.

private function readfileintobytearray(filename:string, data:bytearray):void  {      var infile:file = file.applicationstoragedirectory.resolvepath(filename);        trace (infile.url);      trace (infile.nativepath);      trace (infile.exists); //if file present true else false.      instream.open(infile , filemode.read);     instream.readbytes(data);  } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -