小编Gin*_*ino的帖子

使用 create-react-app 创建新的 React 应用程序时遇到问题

我正在尝试创建一个新的反应项目,但是当我运行时npx create-react-app tik-tok-clone出现以下错误

    Creating a new React app in C:\Users\mwars\Documents\GitHub\TikTok-Clone\tik-tok-clone.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

yarn add v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
error postcss@8.1.3: The engine "node" is incompatible with this module. Expected version "^10 || ^12 || >=14". Got "13.12.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Aborting installation.
  yarnpkg add --exact react react-dom react-scripts cra-template --cwd C:\Users\mwars\Documents\GitHub\TikTok-Clone\tik-tok-clone has …
Run Code Online (Sandbox Code Playgroud)

npm reactjs create-react-app npx

4
推荐指数
1
解决办法
1060
查看次数

使用Cloudinary和Active Storage时如何设置文件上传到特定文件夹?

我明白当使用以下语法直接上传到 Cloudinary 并将文件夹名称作为参数传递时,这是如何下降的。

Cloudinary::Uploader.upload("sample.jpg", :use_filename => true, :folder => "folder1/folder2")
Run Code Online (Sandbox Code Playgroud)

但是,我正在使用 ActiveStorage,当我以上述方式上传照片时,它不会附加到我的Post模型或以任何方式与我的应用程序关联。

我正在使用以下代码附加图像

post.send(:images).attach io: StringIO.new(new_data), filename: blob.filename.to_s, 
          content_type: 'image'
Run Code Online (Sandbox Code Playgroud)

它不接受指定文件夹的参数。我已尽力阅读 ActiveStorage 和 Cloudinary 文档,试图找到一种方法来完成这项工作,但是,我似乎无法弄清楚。

我已经看到设置自定义文件夹标头可能是使其工作的一种方法,但再次无法弄清楚如何为下面发生的上述代码设置自定义标头job

require 'tmpdir'
require 'fileutils'
require 'open-uri'
class ResizeImagesJob < ApplicationJob
  queue_as :default

  def perform(post)
    post.images.each do |image|
      blob = image.blob
      blob.open do |temp_file|
        path = temp_file.path
        pipeline = ImageProcessing::MiniMagick.source(path)
        .resize_to_limit(1200, 1200)
        .call(destination: path)
        new_data = File.binread(path)
        post.send(:images).attach io: StringIO.new(new_data), filename: blob.filename.to_s, 
                           content_type: 'image'
      end
      image.purge_later
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

上述工作正在做的是等到帖子创建后,然后调整照片大小并将照片重新附加到帖子以及删除原始照片。我采用这种方法是为了避免上传后直接在 Cloudinary …

jobs ruby-on-rails http-headers cloudinary rails-activestorage

2
推荐指数
1
解决办法
1783
查看次数