1

Hey there I'm implementing uppy w/ s3 and active storage through this video and I'm not sure what I'm doing wrong.

I'm using stimulus so here's the controller

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);
    });
  }

the div tied to this is

<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>

when I upload things I get this error:

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'

Some things: I have the direct upload url set as:

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

When I run the debugger at line:102 str is an actual var but I'm not sure why it's throwing without the debugger.

Thank you in advance and also my apologies if this is something so basic!

Chris King
  • 95
  • 1
  • 10
  • 2
    Looks like the problem originates [in the controller](https://github.com/rails/rails/blob/main/activestorage/app/controllers/active_storage/direct_uploads_controller.rb#L20), have you checked what `params[: direct_upload_token]`) is up there when you run the code for real? The value is being filtered in the logs but maybe it isn't the scalar it should be. – mu is too short Dec 31 '21 at 04:43
  • Yepp that did the trick. Apparently that param wasn't being sent! – Chris King Jan 01 '22 at 17:20

0 Answers0