带参数的Vue文件上传 [英] Vue File Upload with Parameters

查看:1248
本文介绍了带参数的Vue文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我创建了一个组件来上传文件及其到目前为止的工作,但是我还希望连同数据一起传递一些参数,例如

Hi Guys i create a component to upload files and its working so far, but along with the data I'll like to pass some parameters too, for example

HTML

<div class="col-md-4">
      <div class="container">
        <div class="large-12 medium-12 small-12 cell">
          <label>
            Files
      v-on:click="upload()">Submit</v-btn>
        </div>
      </div>
  </div>

脚本

import
          axios.post('/api/upload', this.files)
      .then(resuta);
    }, error => {
      console.error(error);
    });
  }

在这里(axios.post('/api/upload',this.files))我想包括 电子邮件:this.profile.email

here (axios.post('/api/upload', this.files)) i would like to include email: this.profile.email

因为我要将此参数添加到后端的文件名中

Because I'm adding this parameter to the file name on my backend

控制器

[HttpPost, DisableRequestSizeLimit]
    public ActionResult UploadFile(string email)
    {

        var files = Request.Form.Files;
        foreach (var file in files)
        {

                }
            }

        }
        return Ok();
    }

推荐答案

给出this.files FormData 实例,您应该可以设置您想要的任何字段.例如

Given this.files is a FormData instance, you should be able to set any field you want. For example

upload () {
  this.files.set('email', this.profile.email)

  axios.post('/api/upload', this.files)...

我不太了解.NET MVC,但这会在请求中添加email作为表单参数.

I don't know .NET MVC very well any more but this would add email as a form param in the request.

这篇关于带参数的Vue文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆