我有一个带有 ActionText 和 ActiveStorage 的 Rails 应用程序。所以我有一个带有描述字段的工单表单,其中使用了 ActionText。当我将开发环境配置为将附件保存到本地磁盘时,一切正常。
但是当我将它配置为使用 Azure 存储时,我在日志中看到它似乎已经上传(它返回一个 URL),但是当我在 Azure 中查看时,没有存储图像。这是日志:
Started POST "/rails/active_storage/direct_uploads" for ::1 at 2019-07-30 08:05:37 +0200
Processing by ActiveStorage::DirectUploadsController#create as JSON
Parameters: {"blob"=>{"filename"=>"schaap.jpg", "content_type"=>"image/jpeg", "byte_size"=>56679, "checksum"=>"xNr4chw64aFTDzzvpmupBg=="}, "direct_upload"=>{"blob"=>{"filename"=>"schaap.jpg", "content_type"=>"image/jpeg", "byte_size"=>56679, "checksum"=>"xNr4chw64aFTDzzvpmupBg=="}}}
(0.2ms) BEGIN
ActiveStorage::Blob Create (0.8ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["key", "p83x87l66oibofrfmitfiqet120d"], ["filename", "schaap.jpg"], ["content_type", "image/jpeg"], ["byte_size", 56679], ["checksum", "xNr4chw64aFTDzzvpmupBg=="], ["created_at", "2019-07-30 06:05:38.851532"]]
(0.6ms) COMMIT
AzureStorage Storage (0.9ms) Generated URL for file at key: p83x87l66oibofrfmitfiqet120d (https://<blob name>.blob.core.windows.net/<container-name>/p83x87l66oibofrfmitfiqet120d?sp=rw&sv=2016-05-31&se=2019-07-30T06%3A10%3A38Z&sr=b&sig=%2BicDHTsLBXWCIr00m4cbmcg3U6il5LMfhVcKwTq8dns%3D)
Completed 200 OK in 867ms (Views: 0.4ms | ActiveRecord: 5.7ms | Allocations: 70289)
这是在config/development.rb
:
config.active_storage.service = :local
这是在storage.yml
:
local:
service: AzureStorage
storage_account_name: "<account-name>"
storage_access_key: "<access-key>"
container: "<container>"
并使用了正确的宝石:
gem 'azure-storage', require: false
那么有什么问题呢?我对数字海洋空间进行了同样的尝试,但结果完全相同,因此它与 Azure 无关。