Dropzone prevent aws sign call when file size is bigger then maxFilesize

Viewed 23

I have an issue with nuxt-dropzone using direct aws upload option (https://github.com/Etheryte/nuxt-dropzone). Want to prevent sending request to sign url., if selected file size is bigger then maxFilesize defined in dropzone options

dropzoneOptions: {
    url: `${process.env.API_URL}/nowhere`,
    uploadMultiple: false,
    // previewTemplate: dropzoneTemplate,
    addRemoveLinks: true,
    capture: true,
    params: {},
    maxFiles: this.maxFiles,
    timeout: 9999999999,
    dictDefaultMessage: this.text,
    maxFilesize: this.maxFilesize,
    parallelUploads: this.maxFilesize,
    acceptedFiles: this.accepted,
},

I have aws object defined like

awss3: {
    // signingURL: `${this.$config.apiURL}/sign`,
    signingURL: null,
    headers: {
        Authorization: this.$auth.getToken('myAppToken'),
        Accept: 'application/json',
    },
    params: {
        type: this.type,
    },
    sendFileToServer: false,
    withCredentials: false,
},

And dropzone component used like

dropzone.dropzone(
    id="customdropzone"
    ref="myDropzone"
    :clickable="readonly"
    :awss3="awss3"
    @vdropzone-init="init"
    :class="hasError ? 'has-error' : ''"
    :options="dropzoneOptions"
    @vdropzone-s3-upload-error="s3UploadError"
    @vdropzone-s3-upload-success="s3UploadSuccess"
    @vdropzone-file-added="s3FileAdded"
    @vdropzone-processing="fileProcessing"
    @vdropzone-removed-file="dropzoneRemoveFile"
    @vdropzone-error="dropzoneError"
    @vdropzone-sending="sending"
    @vdropzone-accept="accept"
    duplicate-check
)

So I have tried multiple things till I lost hope and started try silly things :)

first one was to remove file right after it was added (skipped file size check in code just to check, if I can prevent sending sign request to backend)

s3FileAdded(file) {
    EventBus.$emit('fileIsUploading', true)
    this.fileDetails.size = file.size
    file.status = Dropzone.CANCELED // just for test to prevent signing and uploading

    this.$refs.myDropzone.removeAllFiles()
    // or this.$refs.myDropzone.removeFile(file)
    this.file = {
        file_size: file.size,
        original_name: file.name,
        mime_type: file.type,
    }
},

Even without having a file (removed above from dropzone), it's still signing and uploading to s3

Tried to modify file, xhr and formData in sending method (this is calling right before upload after signing), no luck as well

sending(file, xhr, formData) {
    this.$refs.myDropzone.removeFile(file)
    formData = null
    xhr = null
    file = null
    return false
},

no luck again

also tried to mark file as not accepted like below

accept(file, done) {
    if (file) {
        file.status = Dropzone.CANCELED
        throw new Error('Required')
    } else {
        done()
    }
},

Same result, request was sent and file was uploaded to s3.

Any suggestions and thought on this will be appreciated. Thanks

0 Answers
Related