问题
I need to get the uploaded file for pushing it to the list of files, but I'm not able to do it... I hope someone could help me:
UIkit.upload('.test-upload', {
url: `/api/gridfs/${driver}`,
...
completeAll() {
setTimeout(function() {
bar.setAttribute('hidden', 'hidden');
}, 1000);
// Here: fileList.push(???);
}
});
I've tried by different ways, callbacks, etc. but none of them worked. I really don't know how could I get the file!!
Thank you in advance.
回答1:
The upload component has url option. It's the address of the script, which is used to process your request. The upload plugin only deals with frontend. How do you prepare backend, depends on technology you have used. And there inside the script, you prepare response. It can be json with some parameters.
In php it could look like:
//...upload procedures...set headers as text/json etc
$response = ['success' => true, 'filename' => $upload_data['filename']];
echo json_encode($response);
return true;
Then you can check, what goes back in one of the callbacks used by the upload plugin. You place the argument in callback function and try to see with console.log if your json is inside it. Example taken from the docs, and modified a bit:
completeAll: function (arguments) { //added arguments, without it - arguments could be undefined in the line below
console.log('completeAll', arguments);
setTimeout(function () {
bar.setAttribute('hidden', 'hidden');
}, 1000);
alert('Upload Completed');
}
来源:https://stackoverflow.com/questions/45405171/uikit-uploader-getting-the-uploaded-file