Reputation: 81
I am trying to trigger a direct upload via Javascript in my Rails app.
I am putting this at the top of the script in my view:
import { DirectUpload } from "@rails/activestorage"
and get this error:
SyntaxError: import declarations may only appear at top level of a module
Can anyone tell me where I should put the import statement. I am using the asset pipeline.
Upvotes: 0
Views: 260
Reputation: 336
If you want to import DirectUpload
, you should to use webpacker.
When using the asset pipeline, you need to //= require activestorage
. DirectUpload
will then be available via new ActiveStorage.DirectUpload()
.
Upvotes: 1