Javascript 未执行JS类方法(Rails活动存储)
我正在尝试使用直接上传将Uppy文件上传器与Rails ActiveStorage集成。使用Rails文档提供的此代码段:Javascript 未执行JS类方法(Rails活动存储),javascript,ruby-on-rails,rails-activestorage,Javascript,Ruby On Rails,Rails Activestorage,我正在尝试使用直接上传将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.uploa
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
}
}
调用此上载程序类:
const uploader_obj = new Uploader(some_file, some_url)
uploader_obj.upload()
或:
upload(file)方法无法执行。我如何运行此方法?我认为您需要将
upload(file)
类方法重命名为其他方法,因为您有this.upload
和upload(file)
您是如何执行它的?const uploader\u obj=新的uploader(一些文件,一些url)uploader_obj.upload(一些文件)@VadimGalygin你解决了吗?
const uploader_obj = new Uploader(some_file, some_url)
uploader_obj.upload(some_file)