1

嘿,我正在通过这个视频实现 uppy w/s3 和主动存储,我不确定我做错了什么。

我正在使用刺激,所以这里是控制器

import ActiveStorageUpload from "uppy-activestorage-upload";
import { Controller } from "@hotwired/stimulus";
import { post } from "@rails/request.js";
import Uppy from "@uppy/core";
import Dashboard from "@uppy/dashboard";
// https://gorails.com/episodes/uppy-with-active-storage
// Connects to data-controller="s3Direct"
export default class extends Controller {
  static values = { uploadType: String };
  static targets = ["uppy", "imageInput", "uppyTrigger"];
  uploader = new Uppy({
    autoProceed: true,
    allowMultipleUploads: false,
    logger: Uppy.debugLogger,
  });

  connect() {
    console.log("u", ActiveStorageUpload);
    this.uploader.use(ActiveStorageUpload, {
      directUploadUrl: document
        .querySelector("meta[name='direct-upload-url']")
        .getAttribute("content"),
    });
    this.uploader.use(Dashboard, {
      trigger: this.uppyTriggerTarget,
      closeAfterFinish: true,
    });
    this.uploader.on("complete", (result) => {
      console.log(result);
    });
  }

与此相关的 div 是

<div data-controller="s3Direct" data-s3Direct-target="uppy" data-s3Direct-upload-type-value="profile" data-action="s3Direct#loadImage" > 
        <% if @therapist.profile_image.attached? %>
          <%image_tag @therapist.profile_image, width: 280 %>
        <% else %>
          <img src="" alt data-s3Direct-target="preview"/>
        <% end %>
        <p data-s3Direct-target="uppyTrigger" >Upload Your Profile Image</p>
        <%= f.input :profile_image, as: :hidden, input_html: { data: {"s3Direct-target": "imageInput"}} %>
</div>

当我上传东西时,我收到了这个错误:

Started POST "/rails/active_storage/direct_uploads" for 127.0.0.1 at 2021-12-30 18:42:15 -0800
  [1m[36mActiveRecord::SchemaMigration Pluck (2.1ms)[0m  [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
Processing by ActiveStorage::DirectUploadsController#create as JSON
  Parameters: {"blob"=>{"filename"=>"News-256.png", "content_type"=>"image/png", "byte_size"=>7966, "checksum"=>"cknvn+ty0dq5Mk4NcZJ6pA=="}, "direct_upload_token"=>"[FILTERED]", "direct_upload"=>{"blob"=>{"filename"=>"News-256.png", "content_type"=>"image/png", "byte_size"=>7966, "checksum"=>"cknvn+ty0dq5Mk4NcZJ6pA=="}, "direct_upload_token"=>"[FILTERED]"}}
Completed 500 Internal Server Error in 14ms (ActiveRecord: 0.0ms | Allocations: 20422)


  
NoMethodError (undefined method `tr' for #<ActionController::Parameters {} permitted: false>
Did you mean?  try):
  
/Users/chrisking/.rbenv/versions/3.0.3/lib/ruby/3.0.0/base64.rb:102:in `urlsafe_decode64'
activestorage (7.0.0) lib/active_storage/direct_upload_token.rb:52:in `decode_token'
activestorage (7.0.0) lib/active_storage/direct_upload_token.rb:18:in `verify_direct_upload_token'
activestorage (7.0.0) app/controllers/active_storage/direct_uploads_controller.rb:20:in `verified_service_name'
activestorage (7.0.0) app/controllers/active_storage/direct_uploads_controller.rb:10:in `create'
actionpack (7.0.0) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (7.0.0) lib/abstract_controller/base.rb:214:in `process_action'
actionpack (7.0.0) lib/action_controller/metal/rendering.rb:53:in `process_action'
actionpack (7.0.0) lib/abstract_controller/callbacks.rb:234:in `block in process_action'
activesupport (7.0.0) lib/active_support/callbacks.rb:118:in `block in run_callbacks'
actiontext (7.0.0) lib/action_text/rendering.rb:20:in `with_renderer'
actiontext (7.0.0) lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>'
activesupport (7.0.0) lib/active_support/callbacks.rb:127:in `instance_exec'
activesupport (7.0.0) lib/active_support/callbacks.rb:127:in `block in run_callbacks'
activesupport (7.0.0) lib/active_support/callbacks.rb:138:in `run_callbacks'
actionpack (7.0.0) lib/abstract_controller/callbacks.rb:233:in `process_action'
actionpack (7.0.0) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (7.0.0) lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'
activesupport (7.0.0) lib/active_support/notifications.rb:206:in `block in instrument'
activesupport (7.0.0) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (7.0.0) lib/active_support/notifications.rb:206:in `instrument'
actionpack (7.0.0) lib/action_controller/metal/instrumentation.rb:66:in `process_action'
actionpack (7.0.0) lib/action_controller/metal/params_wrapper.rb:259:in `process_action'
activerecord (7.0.0) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (7.0.0) lib/abstract_controller/base.rb:151:in `process'
actionview (7.0.0) lib/action_view/rendering.rb:39:in `process'
actionpack (7.0.0) lib/action_controller/metal/live.rb:266:in `block (2 levels) in process'
activesupport (7.0.0) lib/active_support/concurrency/share_lock.rb:162:in `sharing'
activesupport (7.0.0) lib/active_support/dependencies/interlock.rb:37:in `running'
actionpack (7.0.0) lib/action_controller/metal/live.rb:258:in `block in process'
actionpack (7.0.0) lib/action_controller/metal/live.rb:343:in `block in new_controller_thread'

有些事情:我将直接上传网址设置为:

<%= tag.meta name: "direct-upload-url", content: rails_direct_uploads_path %>

当我在第 102 行运行调试器时,str 是一个实际的 var,但我不确定为什么它会在没有调试器的情况下抛出。

提前感谢您,如果这是如此基本的事情,我也很抱歉!

4

0 回答 0