I have this line of html in my view: <div id="ajax" data-value="photos_path"></div>
And then in my js I do this:
import 'uppy/dist/uppy.min.css'
import '@uppy/core/dist/style.min.css'
import '@uppy/webcam/dist/style.min.css'
import {
Core,
Dashboard,
Webcam,
AwsS3,
} from 'uppy'
function fileUpload(fileInput) {
const hiddenInput = document.querySelector('.upload-data'),
const post_url = document.getElementById('ajax').getAttribute('data-value'),
const s3_url = document.getElementById('s3').getAttribute('data-value')
const uppy = Core({
autoProceed: true,
allowMultipleUploads: true,
restrictions: {
maxFileSize: 10000000,
maxNumberOfFiles: 10,
allowedFileTypes: ['image/jpeg', 'image/png']
}
})
.use(Dashboard, {
inline: true,
target: '#file-uppy',
trigger: '.upload-file',
hideUploadButton: true,
replaceTargetContent: false,
showProgressDetails: true,
width: 1200,
height: 400,
})
.use(Webcam, {
target: Dashboard,
})
.use(AwsS3, {
companionUrl: s3_url,
})
uppy.on('upload-success', (file, response) => {
const uploadedFileData = {
id: file.meta['key'].match(/^cache\/(.+)/)[1], // object key without prefix
storage: 'cache',
metadata: {
size: file.size,
filename: file.name,
mime_type: file.type,
}
}
$.ajax({
type: "POST",
url: post_url,
data: {
photo: {
image: uploadedFileData
}
}
})
})
}
export default fileUpload
Yet for some reason the js is not compiling. I get this error: Uncaught ReferenceError: post_url is not defined
. Seems to me it is defined? In fact I do the same thing for another data value. <div id="s3" data-value="docs"></div>
in the view and s3 = document.getElementById('s3').getAttribute('data-value')
. This works just perfect.
Why does one work and the other does not?