【问题标题】:JS class method not executed (Rails active_storage)JS 类方法未执行(Rails active_storage)
【发布时间】:2018-06-17 20:38:41
【问题描述】:

我正在尝试使用直接上传将 Uppy 文件上传器与 Rails ActiveStorage 集成。使用 Rails 文档提供的这个 sn-p:

import { DirectUpload } from "activestorage"

class Uploader {
  constructor(file, url) {
    this.upload = new DirectUpload(this.file, this.url, this)
  }

  upload(file) {
    this.upload.create((error, blob) => {
      if (error) {
        // Handle the error
      } else {
        // Add an appropriately-named hidden input to the form
        // with a value of blob.signed_id
      }
    })
  }

  directUploadWillStoreFileWithXHR(request) {
    request.upload.addEventListener("progress",
      event => this.directUploadDidProgress(event))
  }

  directUploadDidProgress(event) {
    // Use event.loaded and event.total to update the progress bar
  }
}

调用这个 Uploader 类:

const uploader_obj = new Uploader(some_file, some_url)
uploader_obj.upload()

或者:

const uploader_obj = new Uploader(some_file, some_url)
uploader_obj.upload(some_file)

upload(file) 方法没有被执行。我怎样才能运行这个方法?

【问题讨论】:

  • 你是如何尝试执行它的?
  • const uploader_obj = new Uploader(some_file, some_url) uploader_obj.upload(some_file)
  • @VadimGalygin 你解决了吗?

标签: javascript ruby-on-rails rails-activestorage


【解决方案1】:

我认为您需要将 upload(file) 类方法重命名为其他名称,因为您有 this.uploadupload(file)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 2019-04-15
    • 1970-01-01
    • 2018-11-19
    相关资源
    最近更新 更多