我正在尝试使用直接上传将Uppy文件上传器与Rails ActiveStorage集成。使用Rails docs提供的这个代码段:
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)
上传(文件)方法无法执行。如何运行此方法?
答案 0 :(得分:2)
我认为您需要将upload(file)
类方法重命名为其他方法,因为您有this.upload
和upload(file)