开发者

Is it possible to save files to a network path?

I was wondering if it would be possible to write a file, not to the local 开发者_开发问答system, but to a connected server or other network path.

Would I have to use an external interface for this or can I entrust this to the AIR framework?

I'm pretty sure that AIR has certain security precautions to prevent this.


What kind of network path? SMB, FTP, HTTP, WebDav, .. ?

If it's mounted on your local PC, then you should be able to write to it just like writing to any other drive or filesystem.


to write a new file to a folder on a networked drive in OSX:

var targetDir:File = new File("/Volumes/Data/SomeFolder");
targetDir.createDirectory();  // ensure directory exists, create if not
var targetFile:File = targetDir.resolvePath("newFile.ext");
var fileStream:FileStream = new FileStream();
try {
    fileStream.open(targetFile, FileMode.WRITE);
    fileStream.writeBytes(byteArray);  // or what/however you want to write
    fileStream.close();
} catch (e:Error) {
    trace(e);
}

i assume for Windows you would just swap the network drive path in the first line. you should not specify a protocol (e.g. file://, smb://, etc); the format of the parameter for the File constructor is the native path (as it would appear in a terminal / command shell).

to get the path in OSX, use the Finder to navigate to the target networked folder. begin dragging the folder somewhere else, hit apple+space to open Spotlight, and continue dragging the folder into Spotlight. alternately, open a Terminal window and drag the folder into the Terminal window.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜