我使用Rails + ActiveStorage 上传图片文件,上传后想将宽高保存在数据库中。但是,我无法在任何地方找到任何此类示例。
这是我从各种 API 文档中拼凑出来的,但最终还是出现了这个错误:private method 'open' called for #<String:0x00007f9480610118>. 更换blob用image.file的原因轨登录“跳绳图像分析,因为ImageMagick的不支持文件”(https://github.com/rails/rails/blob/master/activestorage/lib/active_storage/analyzer/image_analyzer.rb#L39) .
代码:
class Image < ApplicationRecord
after_commit { |image| set_dimensions image }
has_one_attached :file
def set_dimensions(image)
if (image.file.attached?)
blob = image.file.download
# error: private method `open' called for #<String:0x00007f9480610118>
meta = ActiveStorage::Analyzer::ImageAnalyzer.new(blob).metadata
end
end
end
Run Code Online (Sandbox Code Playgroud)
这种方法也有问题,因为after_commit它也被称为销毁。
TLDR:上传后是否有立即获取图像元数据的“正确”方法?
在新的GitHub动作中,我试图安装一个软件包,以便在后续步骤之一中使用它。
name: CI
on: [push, pull_request]
jobs:
translations:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Install xmllint
run: apt-get install libxml2-utils
# ...
Run Code Online (Sandbox Code Playgroud)
但是这失败了
Run apt-get install libxml2-utils
apt-get install libxml2-utils
shell: /bin/bash -e {0}
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
##[error]Process completed with exit code 100.
Run Code Online (Sandbox Code Playgroud)
最好的方法是什么?是否需要接触Docker?