I am trying to get the uploaded filename before it's actually uploaded. So i tried to use onBeforeUpload
event and log it to console but nothing returns.
Below is the code I have used. What did I do wrong?
Thank you
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Uppy</title>
<link href="https://releases.transloadit.com/uppy/v1.28.1/uppy.min.css" rel="stylesheet">
</head>
<body>
<div id="drag-drop-area"></div>
<script src="https://releases.transloadit.com/uppy/v1.28.1/uppy.min.js"></script>
<script>
const uppy = Uppy.Core({
debug: true,
autoProceed: true,
restrictions: {
maxFileSize: 2147483647,
maxNumberOfFiles: 5,
minNumberOfFiles: 1,
allowedFileTypes: ['.pdf', '.png', '.jpg', '.jpeg', '.gif']
}
})
.use(Uppy.Dashboard, {
inline: true,
target: '#drag-drop-area'
})
.use(Uppy.Tus, {endpoint: 'https://tusd.tusdemo.net/files/'})
onBeforeUpload: (files) => {
console.log("this is event before upload");
}
uppy.on('complete', (result) => {
console.log('Upload complete! We’ve uploaded these files:', result.successful)
})
</script>
</body>
</html>
You would like to get file for what? Display before upload? Change name? or what?
Did you try put
onBeforeUpload
insideconst uppy = Uppy.Core({...})
? Based on your code i will put it there.Additionally as you can read here
onBeforeFileAdded
is for one file and hereonBeforeUpload
is for all files.If you would like to display files before it is uploaded you can use file-added or files-added event.
Example: