替代对FileReference.save锁定的文件类型()AS3文件类型、FileReference、save

2023-09-08 12:29:32 作者:傻不拉几

更新:

正如下面雅各布的回复讨论,限制或纠正FileReference.save的行为是不可能的。任何人都可以提出一个替代方案(服务器就是Apache / PHP)符合我所有的标准,从这篇文章,避免了我与雅各布讨论的陷阱?

As discussed in Jacob's reply below, limiting or correcting the behaviour of FileReference.save isn't possible. Can anyone suggest an alternative (server is Apache/PHP) that matches all of my criteria from this post and avoids the pitfalls I discussed with Jacob?

编辑完

我是从我的AS3应用程序中使用FileReference.save保存图像()。这是code,它工作正常:

I'm saving an image from my AS3 app using FileReference.save(). This is the code, which works fine:

var encoder:JPGEncoder = new JPGEncoder(80);
var byteData = encoder.encode(myBMD);  //bitmap data object created earlier
var file:FileReference = new FileReference();
file.save(byteData, "myImage.jpg");

这开辟了预期的保存文件对话框。我用这个,而不是发送byteData到PHP,因为我希望用户有一个熟悉的对话框,让他们建立自己的文件名。

This opens up the save file dialog as expected. I'm using this rather than sending the byteData to PHP because I want the user to have a familiar dialog box that lets them set their own file name.

的问题是当用户拥有自己的操作系统配置为显示文件扩展名,像我这样做。这意味着,在保存对话框的文件名中包含扩展的图像中看到的下方,所以它很容易让用户删除该分机时,他们重命名文件。因为默认的文件类型为这个盒子是所有文件,如果扩展被删除的文件被保存,没有类型。

The problem comes when users have their operating system configured to display file extensions, like I do. This means that in the save dialog the file name contains the extension as seen in the image below, and so it is very easy for the user to delete that extension when they rename the file. Because the default file type for this box is 'All files', if the extension is deleted the file is saved with no type.

我不知道有什么办法强迫保存对话框上的文件类型(如果存在的话,这将是我的preferred路径),这样做不到这一点任何人都可以提出一个安全的方式为我做这一点,仍然允许用户使用一个标准的对话框在他们的操作系统来为自己的文件名?

I don't know of any way to force a file type on the save dialog (if there is one that would be my preferred route) so failing that can anyone suggest a safe way for me to do this that still allows the user to set the file name themselves using a standard dialog for their OS?

我也尝试投入调用调用FileReference.browse()之前保存(),如图this教程,而是抛出一个错误,因为你只能在一个时间执行一个的FileReference电话。

I did try putting in a call to FileReference.browse() before the save() as shown in this tutorial, but that throws an error because you can only perform one FileReference call at a time.

推荐答案

很抱歉,这是一个已知的,主要的闪存播放器的错误,没有真正的解决办法。

Sorry this is a known, major flash player bug with no real workaround.

投票在这里:的 https://bugs.adobe.com/jira/browse/FP-2014

(虽然由于某些原因,Adobe正在调用它的功能要求。)

(Though for some reason, Adobe is calling it a feature request.)

编辑2:的

固定的FP 11.8 Chrome浏览器,同时支持Mac OS和Windows上。

Fixed for FP 11.8 for Chrome, on both Mac OS and Windows.

https://bugbase.adobe.com/index.cfm?事件=错误和ID = 2898055

编辑:添加的NavigateTo解决办法的信息的

有这样做的PHP选项​​的NavigateTo():张贴文件到PHP网页,其中有一个MIME类型图像/ JPEG 如果指定了正确的头,你可以让浏览器打开浏览器本地保存对话框,确实维护扩展。但是,也有其他的缺点该方法

There is the php option of doing a navigateTo(): posting the file to a php page which has a mime-type of image/jpeg If you specify the right headers, you can get the browser to bring up the browser's native save dialog which does maintain extensions. However, there are other drawbacks to that method:

没有错误从Flex内处理 征求意见函时间 在增加服务器负载。 没有反馈给用户,而该文件被上传并重新下载。 在不同浏览器/操作系统不一致的用户体验。 在一些浏览器会弹出实际上一个新的窗口,该窗口消失 在一些会离开窗口。 在一些不会有任何新的窗口可言。 no error handling from within flex additional request time additional server load. no feedback to user while the file is being uploaded and re-downloaded. inconsistent user experience across browser/os. some browsers will actually popup a new window that disappears some will leave the window. some won't have any new window at all.