簡體   English   中英

JS 類方法未執行(Rails active_storage)

[英]JS class method not executed (Rails active_storage)

我正在嘗試使用直接上傳將 Uppy 文件上傳器與 Rails ActiveStorage 集成。 使用 Rails 文檔提供的這個片段:

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)類方法重命名為其他方法,因為您有this.uploadupload(file)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM