# Uploads administration

> 原文：[https://docs.gitlab.com/ee/administration/uploads.html](https://docs.gitlab.com/ee/administration/uploads.html)

*   [Using local storage](#using-local-storage)
*   [Using object storage](#using-object-storage-core-only)
*   [Object Storage Settings](#object-storage-settings)
    *   [Connection settings](#connection-settings)
    *   [OpenStack example](#openstack-example)

# Uploads administration[](#uploads-administration "Permalink")

上传代表可以作为单个文件发送到 GitLab 的所有用户数据. 例如，化身和笔记的附件就是上载. 上传是 GitLab 功能不可或缺的，因此不能被禁用.

## Using local storage[](#using-local-storage "Permalink")

**注意：**这是默认配置

要更改上传内容在本地存储的位置，请按照以下步骤操作.

**在所有安装中；**

**注意：**由于历史原因，上载存储在基本目录中，默认情况下该目录为`uploads/-/system` . 不建议在现有的 GitLab 安装上更改此配置选项.

*上载默认情况下存储在`/var/opt/gitlab/gitlab-rails/uploads` .*

1.  要将存储路径更改为例如`/mnt/storage/uploads` ，请编辑`/etc/gitlab/gitlab.rb`并添加以下行：

    ```
    gitlab_rails['uploads_storage_path'] = "/mnt/storage/"
    gitlab_rails['uploads_base_dir'] = "uploads" 
    ```

2.  保存文件并[重新配置 GitLab，](restart_gitlab.html#omnibus-gitlab-reconfigure)以使更改生效.

**在源安装中：**

*上载默认存储在`/home/git/gitlab/public/uploads/-/system` .*

1.  要将存储路径更改为例如`/mnt/storage/uploads` ，请编辑`/home/git/gitlab/config/gitlab.yml`并添加或修改以下行：

    ```
    uploads:
      storage_path: /mnt/storage
      base_dir: uploads 
    ```

2.  保存文件并[重新启动 GitLab，](restart_gitlab.html#installations-from-source)以使更改生效.

## Using object storage[](#using-object-storage-core-only "Permalink")

版本历史

**笔记：**

*   在[GitLab Premium](https://about.gitlab.com/pricing/) 10.5 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/3867) .
*   在[GitLab Core](https://about.gitlab.com/pricing/) 10.7 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/17358) .
*   从 11.1 版开始，我们支持 direct_upload 到 S3\.

如果您不想使用安装了 GitLab 的本地磁盘来存储上载，则可以改用 AWS S3 之类的对象存储提供程序. 此配置依赖于已经配置的有效 AWS 凭证.

[Read more about using object storage with GitLab](object_storage.html).

**注意：**我们建议使用[统一对象存储设置](object_storage.html#consolidated-object-storage-configuration) . 以下说明适用于原始配置格式.

## Object Storage Settings[](#object-storage-settings "Permalink")

对于源安装，以下设置嵌套在`uploads:`下，然后是`object_store:` 在 Omnibus GitLab 安装上，它们的前缀是`uploads_object_store_` .

| Setting | Description | Default |
| --- | --- | --- |
| `enabled` | 启用/禁用对象存储 | `false` |
| `remote_directory` | 存储上传文件的存储桶名称 |   |
| `direct_upload` | 设置为 true 可从上载路径中删除 Puma. Workhorse 处理实际的工件上传到对象存储，而 Puma 进行最少的处理以跟踪上传. 无需本地共享存储. 如果引入了对所有文件的单一存储类型的支持，则可以删除该选项. 了解更多有关[直接上传的信息](../development/uploads.html#direct-upload) . | `false` |
| `background_upload` | 设置为 false 可禁用自动上传. 一旦直接上传到 S3，就可以删除该选项（如果`direct_upload`设置为`true` ，它将覆盖`background_upload` ） | `true` |
| `proxy_download` | 设置为 true 以启用代理服务的所有文件. Option 可以减少出口流量，因为这允许客户端直接从远程存储下载而不是代理所有数据 | `false` |
| `connection` | 下述各种连接选项 |   |

### Connection settings[](#connection-settings "Permalink")

See [the available connection settings for different providers](object_storage.html#connection-settings).

**在所有安装中；**

*上载默认情况下存储在`/var/opt/gitlab/gitlab-rails/public/uploads/-/system` .*

1.  编辑`/etc/gitlab/gitlab.rb`并通过替换为所需的值添加以下行：

    ```
    gitlab_rails['uploads_object_store_enabled'] = true
    gitlab_rails['uploads_object_store_remote_directory'] = "uploads"
    gitlab_rails['uploads_object_store_connection'] = {
      'provider' => 'AWS',
      'region' => 'eu-central-1',
      'aws_access_key_id' => 'AWS_ACCESS_KEY_ID',
      'aws_secret_access_key' => 'AWS_SECRET_ACCESS_KEY'
    } 
    ```

    **注意：**如果您使用的是 AWS IAM 配置文件，请确保省略 AWS 访问密钥和秘密访问密钥/值对.

    ```
    gitlab_rails['uploads_object_store_connection'] = {
      'provider' => 'AWS',
      'region' => 'eu-central-1',
      'use_iam_profile' => true
    } 
    ```

2.  保存文件并[重新配置 GitLab，](restart_gitlab.html#omnibus-gitlab-reconfigure)以使更改生效.
3.  使用[`gitlab:uploads:migrate` Rake task](raketasks/uploads/migrate.html)迁移所有现有的本地上传到对象存储.

**在源安装中：**

*上载默认存储在`/home/git/gitlab/public/uploads/-/system` .*

1.  编辑`/home/git/gitlab/config/gitlab.yml`并添加或修改以下行：

    ```
    uploads:
      object_store:
        enabled: true
        remote_directory: "uploads" # The bucket name
        connection:
          provider: AWS # Only AWS supported at the moment
          aws_access_key_id: AWS_ACESS_KEY_ID
          aws_secret_access_key: AWS_SECRET_ACCESS_KEY
          region: eu-central-1 
    ```

2.  保存文件并[重新启动 GitLab，](restart_gitlab.html#installations-from-source)以使更改生效.
3.  使用[`gitlab:uploads:migrate` Rake task](raketasks/uploads/migrate.html)迁移所有现有的本地上传到对象存储.

### OpenStack example[](#openstack-example "Permalink")

**在所有安装中；**

*上载默认情况下存储在`/var/opt/gitlab/gitlab-rails/public/uploads/-/system` .*

1.  Edit `/etc/gitlab/gitlab.rb` and add the following lines by replacing with the values you want:

    ```
    gitlab_rails['uploads_object_store_remote_directory'] = "OPENSTACK_OBJECT_CONTAINER_NAME"
    gitlab_rails['uploads_object_store_connection'] = {
     'provider' => 'OpenStack',
     'openstack_username' => 'OPENSTACK_USERNAME',
     'openstack_api_key' => 'OPENSTACK_PASSWORD',
     'openstack_temp_url_key' => 'OPENSTACK_TEMP_URL_KEY',
     'openstack_auth_url' => 'https://auth.cloud.ovh.net/v2.0/',
     'openstack_region' => 'DE1',
     'openstack_tenant' => 'TENANT_ID',
    } 
    ```

2.  保存文件并[重新配置 GitLab，](restart_gitlab.html#omnibus-gitlab-reconfigure)以使更改生效.
3.  使用[`gitlab:uploads:migrate` Rake task](raketasks/uploads/migrate.html)迁移所有现有的本地上传到对象存储.

* * *

**在源安装中：**

*上载默认存储在`/home/git/gitlab/public/uploads/-/system` .*

1.  编辑`/home/git/gitlab/config/gitlab.yml`并添加或修改以下行：

    ```
    uploads:
      object_store:
        enabled: true
        direct_upload: false
        background_upload: true
        proxy_download: false
        remote_directory: OPENSTACK_OBJECT_CONTAINER_NAME
        connection:
          provider: OpenStack
          openstack_username: OPENSTACK_USERNAME
          openstack_api_key: OPENSTACK_PASSWORD
          openstack_temp_url_key: OPENSTACK_TEMP_URL_KEY
          openstack_auth_url: 'https://auth.cloud.ovh.net/v2.0/'
          openstack_region: DE1
          openstack_tenant: 'TENANT_ID' 
    ```

2.  保存文件并[重新配置 GitLab，](restart_gitlab.html#omnibus-gitlab-reconfigure)以使更改生效.
3.  使用[`gitlab:uploads:migrate` Rake task](raketasks/uploads/migrate.html)迁移所有现有的本地上传到对象存储.