tomitrescak / meteor-uploads

MIT License
295 stars 41 forks source link

Validation not working #157

Closed CheeseBurger228 closed 8 years ago

CheeseBurger228 commented 9 years ago

Hello, first i want to say that this package is great!! I'm using this package and i want to setup the validation for the uploaded files, to check if they are images, and check that files are uploaded on client.

If i try to use server methods:

 validateFile: function(req)
 {
        console.log(req.type);
        if(req.type=="image/png" || req.type=="image/jpg" || req.type=="image/jpeg")
        {
            return true;
       }
       return false;
 }

I get the error like this if image is uploaded:

/home/golden-credit.org/.meteor/local/build/programs/server/packages/tomi_upload-server.js:370 W20151001-11:05:35.716(3)? (STDERR) res.writeHead(403, {'Content-Type': 'text/plain'}); W20151001-11:05:35.716(3)? (STDERR) ^ W20151001-11:05:35.733(3)? (STDERR) ReferenceError: res is not defined W20151001-11:05:35.733(3)? (STDERR) at IncomingForm.form.on.on.redirect (packages/tomi:upload-server/upload_server.js:350:1)

I also tried to use the client-side validation, to check if the user uploaded file in template, like so:

Template.multiStepForm.helpers({

myCallbacks: function() {
    return {
        validate: function(file)
        {
            if(!file)
            {
                alert("FAIL");
            }
        }
     }
  }
});

and in html:

   <div class="form-group">
                            {{> upload_bootstrap callbacks=myCallbacks contentType='images'  fileTypes='image/*' formData=userFormData}}
    </div>

But it breaks the upload script somehow, when i set 'callbacks=myCallbacks' i can no longer upload file, if i select the file, it doesnt appera in input box etc. How do you use it properly, am i doing something wrong??

tomitrescak commented 9 years ago

Duplicate of #148

CheeseBurger228 commented 9 years ago

Are you sure it's a duplicate? I do not understand, i mean i don't have any issues with form data, everything works fine, but not validation callbacks

tomitrescak commented 8 years ago

@CheeseBurger228 I am sorry for a very late response but I've been "out in the wild" and had no time to do any of the work on the plugin. I'm pretty sure you have solved everything by now. I have recently updated the plugin to deal with ALL the issues that you mention ... and also updated the documentation which did not make clear that validation has to return an error message in case of failed validation, thus returning "true" actually means that the validation has failed. I have also handled problem with res is null error. Please report back if problems persist.