I have a server side service that receives file uploads and does validations on the contents of the zip files. The validation may include multiple messages with the type being success, warning and error.
Here is the current code in my polymer component using vaadin-upload that I am using:
window.addEventListener('WebComponentsReady', function() {
var upload = document.querySelector('vaadin-upload#responseDemo');
upload.addEventListener('upload-response', function(event) {
var results = JSON.parse(event.detail.xhr.response);
console.log('upload xhr after server response: ', event.detail.xhr);
if (results[0].messages.length > 0) {
event.detail.file.error = "";
for (var i = 0; i < results[0].messages.length; i++) {
if (i > 0) {
event.detail.file.error += ";";
}
event.detail.file.error += results[0].messages[i].message;
}
}
// Interpret any server response as success:
// event.detail.xhr.status = 200;
});
});
Here is the format of the results coming back from the service:
[
{
"name": "foo.zip",
"messages": [
{
"type": "error",
"message": "no store.csv metadata found"
}
]
}
]
If there are any messages of type error, then it should show failure for the upload of the file. If there are only warnings and successes, then the upload should have an icon with the warning. If there are no messages or messages of only success, then the file upload should be marked as success.
I am currently using polymer 1, but will be upgrading to polymer 3 soon.