javascript—当我在filemanager plunig中使用vue.js时,如何将文件上载到服务器,或者如何调用全局函数?

fumotvh3  于 2021-09-23  发布在  Java
关注(0)|答案(1)|浏览(278)

当我在filemanager plunig中使用vue.js时,如何将文件上载到服务器?
我尝试了更多的方法和控制台日志显示上传成功,但我在服务器上看不到任何文件,谁知道发生了什么?

<template>
  <div class="FileManagement" id="file-manager" name="file-manager">
    <va-inner-loading :loading="isLoading">
      <div class="row">
        <div class="flex xs12 md12">
          <DxFileManager
            ref="fileManager"
            name="file"
            :file-system-provider="fileSystemProvider"
            current-path="Widescreen"
          >
            <DxPermissions
              :create="true"
              :copy="false"
              :move="false"
              :delete="true"
              :rename="false"
              :upload="true"
              :download="true"
            />
          </DxFileManager>
        </div>
      </div>
    </va-inner-loading>
  </div>
</template>
data() {
    return {
      isLoading: false,
      // fileSystemProvider: [],
      popupVisible: false,
      imageItemToDisplay: {},
      result: [],
      fileSystemProvider: new CustomFileSystemProvider({
        getItems,
        createDirectory,
        uploadFileChunk,
        onCurrentDirectoryChanged,
        downloadItems,
        renameItem,
        deleteItem,
      }),
    };
  },
  mounted() {
    this.initEvent();
  },
  methods: {
}

function uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
  let self = this;
let formData = new FormData();
  formData.append("name", fileData.name);
  formData.append("file", fileData);

  let config = {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  };

  axios.post("/files/upload", formData, config).then(function (response) {
    if (response.status === 200) {
      console.log(response.data);
    }
  });
}

在我的global.vue中,我有一个this函数,但是如何在filemanager.vue中用方法()调用此函数呢?

Global.vue
onUploadFile: function (
//code
) 

FileManager.vue
mounted() {},
methods: {},
function uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
 // how can call global onUploadFile: function  ???
}

一般的
请求url:http://192.168.1.120/files/upload/ 请求方法:获取状态代码:200确定远程地址:192.168.1.120:80参考者策略:交叉来源时严格来源

or may I use javascript mehtods to upload the file?

====================================================================

to RuNpiXelruN, I did your methods to modify my code, and it was show me successful, but the server still didn't had file.

一般的
请求url:http://192.168.1.120/files/upload/ 请求方法:post状态代码:301已永久移动远程地址:192.168.67.164:80推荐人策略:交叉来源时严格来源

uqcuzwp8

uqcuzwp81#

@詹姆斯,告诉你,你做下面的事

formData.append("file", fileData, fileData.name)

否则,将标题改为下面,看看是否成功。

'Content-Type': 'application/x-www-form-urlencoded'

相关问题