robot file/filter custom error message not show

Archived from the Transloadit support forum. Originally posted on October 29, 2013; details may be outdated, see our docs for current behavior. Original thread

Hi all,

I created a simple filter to check file extension and give error if file extension is not accepted.
The problem is that tansload seem to ignore “error_msg” parameter because when i test template, i really get error box but with standard message and not my custom message of “error_msg”.
Is this a bug?

best
Francisco Azevedo

Hey Francisco,

can you please post the relevant code?

Tim, i’m using transloadit template tester :slight_smile:

Francisco Azevedo

Here goes a simple example:

"steps": {
    "files": {
      "robot": "/file/filter",
      "accepts": [
        [
          "${file.ext}",
          "==",
          "png"
        ]
      ],
      "error_on_decline": true,
      "error_msg": "Only png files are permitted"
    },
...

When i create a template with this sample code and try to test it on transloadit user-area, i get uploader standard error message when file is not “png” instead of “Only png files are permitted” message.

Best,
Francisco Azevedo

Hi again,

I think i found a strange behaviour with file/filter.
Eg, imagine i want to use swf files (note this is just an example) and make sure uploaded files must be flash.. so with a mimetype “application/x-shockwave-flash”.

The problem is that, if i use “==” i get a transloadit parse error “Transloadit was unable to parse your accepts or declines array”.

If i use “regex” it works as expected.

Sounds strange to me..

Problem:
@@@
“steps”: {
“files”: {
“robot”: “/file/filter”,
“accepts”: [
[
“${file.mime}”,
“==”,
“application/x-shockwave-flash”
]
],
“error_on_decline”: true,
“error_msg”: “Only swf files are permitted”
},
…
@@@

This version, works as expected:

@@@

"steps": {
"files": {
"robot": "/file/filter",
"accepts": [
[
"${file.mime}",
"regex",
"application/x-shockwave-flash"
]
],
"error_on_decline": true,
"error_msg": "Only swf files are permitted"
},

…
@@@

Shouldn’t “file/parse” robot compare mime exact string with “==” operator instead of giving error? Why is this happening?

With “regex” i get my problem solved.

Best,
Francisco Azevedo

Hey Francisco,

the operator must be “=” and not “==” as per our docs.

But I see how people can get this wrong, so we are going to make “==” available, too.
I just tested it again using “=” and it works as expected.

Kind regards,
Tim

Co-Founder Transloadit
@tim_kos

Hi Tim,

You are right, we should use “=” instead of “==”.
It’s working now. Thanks.

Best,
Francisco Azevedo

Most welcome.

I also made “==” and “===” work in the meantime.

Closing this.

Kind regards,
Tim

Co-Founder Transloadit
@tim_kos