2

I am trying to restrict the file type (only mp3 files) when I open a dialog with uploadcare.

 uploadcare.loadFileGroup(soundGroupID) .done(function (fileGroup) { uploadcare.openDialog(fileGroup.files(), { multiple: true, multipleMin: 0, fileTypes="mp3" }).done( function (file) { file.promise().done( function (fileInfo) { //TODO Something }); }); }) .fail(function () { // Something went wrong. }); 

Is there any way to push a validator? Is there any way to access the widget? As you can see, I am opening a dialog so I can not access the widget anywhere.

1
  • if it passes an accept param into the file input's attrib you're golden. Commented Nov 10, 2014 at 18:52

1 Answer 1

2

Unfortunately there is no validators for dialogs in current API, only for widgets. But you can create fake widget and use .openDialog() method on it.

uploadcare.loadFileGroup(soundGroupID) .done(function (fileGroup) { var widget = uploadcare.MultipleWidget('<input data-multiple multiple-min="1">'); widget.validators.push(function(info) { if (info.name !== null) { if ( ! /\.mp3$/i.test(info.name)) { throw Error('mp3-only'); } } }); widget.openDialog(null).done( function (file) { file.promise().done( function (fileInfo) { //TODO Something }); }); }) .fail(function () { // Something went wrong. }); 

Alternatively, you can pass list of validators in private __validators option, but this is internal API and can be changed in future versions.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.