Skip to content

ARCHIVED

!注意“归档”

This chapter has not been updated for the current version of Orchard, and has been ARCHIVED.

Media storage

媒体存储

When storing media such as images, there are basically two choices: the file system or the database.

存储图像等媒体时,基本上有两种选择:文件系统或数据库。

Database storage

数据库存储

The database storage has the advantage that it's relatively easier to set-up and to not require additional writing privileges. When media are attached to other database-bound objects such as a contents page, it also makes the management a little easier as the association between the object and the media it uses is explicit. On the other hand, such a structure also makes it more difficult to reuse media across objects.

数据库存储的优点是设置起来相对容易,并且不需要额外的写入权限。当媒体附加到其他数据库绑定对象(例如内容页面)时,它也使管理变得更容易,因为对象与其使用的媒体之间的关联是显式的。另一方面,这种结构也使得跨对象重用媒体变得更加困难。

Database storage also provides great freedom to add arbitrary metadata and also handle multiple revisions, drafts, etc.

数据库存储还提供了添加任意元数据以及处理多个修订,草稿等的极大自由。

To properly scale, a database storage for media will probably have to implement many features of a file system, which may be expensive to implement.

为了适当地扩展,用于媒体的数据库存储可能必须实现文件系统的许多功能,这可能实现起来很昂贵。

From the end-user management perspective, the database is a black box. The web interface being the only way to explore the contents can be seen as a disadvantage.

从最终用户管理的角度来看,数据库是一个黑盒子。 Web界面是探索内容的唯一方式,可以看作是一个缺点。

Uploading tools are also more constrained with a database storage: with the file system, any FTP tool can upload, in addition to web-based uploads. With database storage, only web uploads are possible. XML-RPC APIs such as the Atom Publishing Protocol are appearing though, enabling media publishing from non-web-based tools.

上传工具也受到数据库存储的限制:除了基于Web的上传之外,使用文件系统,任何FTP工具都可以上传。使用数据库存储,只能进行Web上传。虽然出现了[Atom Publishing Protocol](http://tools.ietf.org/html/rfc5023)等XML-RPC API,但可以从非基于Web的工具中进行媒体发布。

Another problem with the database storage is performance: IIS serves static files a lot faster than dynamic resources.

数据库存储的另一个问题是性能:IIS比动态资源更快地提供静态文件。

File system storage

文件系统存储

Storing media in the file system looks like a natural choice. It makes it very easy to manage the files, even without using the application: open an FTP client, navigate to the contents/media folder and explore at will.

在文件系统中存储媒体看起来是一种自然的选择。即使不使用应用程序,也可以非常轻松地管理文件:打开FTP客户端,导航到contents / media文件夹并随意浏览。

File system storage also enables the application to associate content entities with the media they use by automatically creating folders with the entities' slugs but the association is less robust than with database storage: there is no reference integrity checks and it is possible to delete the media and end up with the dreaded red crosses in web pages. Similarly, if the content goes away and the media are not deleted, this might lead the media folder to slowly rot.

文件系统存储还使应用程序能够通过使用实体的slug自动创建文件夹,将内容实体与其使用的媒体相关联,但关联不如数据库存储更强大:没有参考完整性检查,可以删除媒体并最终在网页上的可怕的红色十字架。同样,如果内容消失且媒体未被删除,则可能导致媒体文件夹慢慢腐烂。

Metadata can be managed in the database even if the media is in the file system, but that also leads to integrity problems. Metadata can also be managed with files next to the media files. Finally, most media formats support meta-data right in the media file. For example, photographic formats support EXIF data. Meta-data is best handled using the storage that the media format already provides, as the workflow that produces those media files already uses tools that understand native embedded meta-data formats.

即使媒体位于文件系统中,也可以在数据库中管理元数据,但这也会导致完整性问题。还可以使用媒体文件旁边的文件管理元数据。最后,大多数媒体格式都支持媒体文件中的元数据。例如,照片格式支持EXIF数据。元数据最好使用媒体格式已经提供的存储来处理,因为生成这些媒体文件的工作流已经使用了解本机嵌入式元数据格式的工具。

File system or database?

文件系统还是数据库?

That decision could actually be abstracted away by virtual path providers but those don't run in medium trust on .NET 3.5. Effectively, they will be abstracted away from the outside as they will be available through XML-RPC APIs. Without using virtual path providers, it is still possible to go with an abstraction, enabling for database storage even if our default implementation is the file system.

该决定实际上可以被虚拟路径提供程序抽象掉,但那些不能在.NET 3.5上以中等信任运行。实际上,它们将从外部抽象出来,因为它们将通过XML-RPC API提供。在不使用虚拟路径提供程序的情况下,即使我们的默认实现是文件系统,仍然可以使用抽象,启用数据库存储。

As the default, we are implementing the file system storage, with a thin abstraction layer to still allow for alternative implementations and easier testing.

默认情况下,我们正在实现文件系统存储,使用精简抽象层仍然允许替代实现和更容易的测试。

Scenarios

方案

From the page editor, I can upload an image and insert it into a content zone

在页面编辑器中,我可以上传图像并将其插入内容区域

Users must be able to upload and use media in their contents without leaving the page editor. The goal of this scenario is that the online content editing experience is on par with the LiveWriter experience.

用户必须能够在不离开页面编辑器的情况下在其内容中上载和使用媒体。此场景的目标是在线内容编辑体验与LiveWriter体验相同。

In the case where JavaScript is enabled, a rich text editor is displayed in admin UI to edit contents. This rich-text editor will be extended to add an "Upload picture" button to the editor's toolbar. Pressing this button will bring an overlay dialog that contains a file upload field and an "Upload" button. The user would click "browse" on the upload field, would navigate to a file on his local hard drive, select it and then click OK to close the choose file dialog. He would then click "Upload". The image would then be uploaded, and on completion, would be automatically inserted into the contents being edited at the position of the caret.

在启用JavaScript的情况下,在管理UI中显示富文本编辑器以编辑内容。这个富文本编辑器将扩展为向编辑器的工具栏添加“上传图片”按钮。按此按钮将显示一个叠加对话框,其中包含文件上载字段和“上载”按钮。用户可以单击上载字段中的“浏览”,导航到本地硬盘驱动器上的文件,选择它,然后单击“确定”关闭“选择文件”对话框。然后他会点击“上传”。然后上传图像,并在完成时,将自动插入在插入符号位置编辑的内容中。

The location on the site where the media get uploaded would be similar to the case of LiveWriter post creation. That means in particular that a folder gets auto-created from the slug to contain the uploaded files. For a blog post, the uploading location could be: /media/[slugOfMyBlog]/[SlugOfMyPost]/[ImageFileName].[extension (jpg, png, etc.)].

媒体上传的网站上的位置与LiveWriter帖子创建的情况类似。这意味着特别是从slug自动创建一个文件夹以包含上传的文件。对于博客文章,上传位置可以是:/media/\[slugOfMyBlog\]/\[SlugOfMyPost\]/\[ImageFileName\]\.\[extension \(jpg,png,etc \。\)\]。

If an image with the same name already exists in the uploading folder, a number gets automatically appended to the file name to make it unique.

如果上载文件夹中已存在具有相同名称的图像,则会自动将数字附加到文件名以使其唯一。

Note: Flow 1 below represents a non-JavaScript scenario for the same thing, which we won't implement at this time.

注意:下面的流程1表示同一事物的非JavaScript场景,我们目前不会实现。

From the page editor, I can browse to an existing image and insert it into a content zone

在页面编辑器中,我可以浏览到现有图像并将其插入到内容区域中

See flow 2 below. Media can be reused across different pieces of contents.

见下面的流程2。媒体可以在不同的内容中重复使用。

I can manage the files on the site

我可以管理网站上的文件

See flow 2 below. Media management has its own specialized management UI.

见下面的流程2。媒体管理有自己的专业管理UI。

When JavaScript is off, I can still upload an image and get its URL as a result, which I can use in an img tag

当JavaScript关闭时,我仍然可以上传图像并获取其URL作为结果,我可以在img标记中使用它

See flow 1 below. Embedding media in contents is easy with or without JavaScript.

见下面的流程1。无论是否使用JavaScript,都可以轻松地将媒体嵌入到内容中。

Permissions

权限

In this context, owner means the media asset owner when acting on a specific asset, or the folder owner otherwise.

在此上下文中,所有者表示在处理特定资产时的媒体资产所有者,否则表示文件夹所有者。

Note: Front-end viewing permissions for media are out of the scope of Orchard permissions because media are being served directly by IIS without intervention of the ASP.NET pipeline. Thus, the view permissions for media really are file-level permissions and should be managed at that level if the need arises.

注意:媒体的前端查看权限超出了Orchard权限的范围,因为IIS直接提供媒体,而无需ASP.NET管道的干预。因此,媒体的视图权限实际上是文件级权限,如果需要,应该在该级别进行管理。

Default permissions are:

默认权限是:

Permission | Anon. | Authentic. | Owner | Admin. | Author | Editor

许可|匿名。 |真实。 |所有者|管理员。 |作者|编辑

------------------------------------------------ | ----- | ---------- | ----- | ------ | ------ | ------

  • | ----- | ---------- | ----- | ------ | ------ | ------

Upload & manage media (modify/rename/delete) | No | No | Yes | Yes | Yes | Yes

上传和管理媒体(修改/重命名/删除)|没有|没有|是的|是的|是的|是

Create and manage media folders | No | No | Yes | Yes | Yes | No

创建和管理媒体文件夹|没有|没有|是的|是的|是的|没有

Flows

流动

Flow 1: media uploading and embedding with JavaScript disabled from the page editor

流程1:从页面编辑器禁用了媒体上载和嵌入JavaScript

Flow 2: media management

流程2:媒体管理