本文介绍了UIkit上载器:获取上载的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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!!

谢谢.

推荐答案

上载组件具有url选项.这是脚本的地址,用于处理您的请求.上传插件仅处理前端.您如何准备后端,取决于您使用的技术.在脚本中,您可以准备响应.可以是带有某些参数的json.

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.

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

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;

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

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');
  }

这篇关于UIkit上载器:获取上载的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 03:24