0

我需要获取上传的文件以将其推送到文件列表中,但我无法做到......我希望有人可以帮助我:

UIkit.upload('.test-upload', {
   url: `/api/gridfs/${driver}`,

   ...

   completeAll() {
      setTimeout(function() {
         bar.setAttribute('hidden', 'hidden');
      }, 1000);

      // Here: fileList.push(???);
   }
});

我尝试过不同的方式、回调等,但没有一个奏效。我真的不知道我怎么能得到文件!

先感谢您。

4

1 回答 1

1

上传组件有 url 选项。它是脚本的地址,用于处理您的请求。上传插件只处理前端。您如何准备后端,取决于您使用的技术。在脚本内部,您准备响应。它可以是带有一些参数的json。

在 php 中,它可能看起来像:

//...upload procedures...set headers as text/json etc
$response = ['success' => true, 'filename' => $upload_data['filename']];
echo json_encode($response);
return true;

然后您可以检查上传插件使用的回调之一中的内容。您将参数放在回调函数中,并尝试使用 console.log 查看您的 json 是否在其中。示例取自文档,并稍作修改:

 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');
  }
于 2017-08-03T19:38:37.827 回答