从expressJs中的表单数据请求获取Blob数据

时间:2020-08-17 20:40:49

标签: node.js ajax rest express

现在我正在使用ajax作为formdata将文件发送到我的expressjs服务器。

from bokeh.io import output_notebook, output_file, show
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.transform import dodge

output_notebook() # or output_file("chart.html") if not using Jupyter

x_axis_values = [str(x) for x in range(1, 6)]

data = {
    "Coordination Number" : x_axis_values,
    "Green"               : [1, 2, 3, 4, 5],
    "Yellow"              : [3, 4, 1, 10, 9],
    "Red"                 : [6, 7, 2, 4, 6]
}

src = ColumnDataSource(data=data)

p = figure(
    x_range=x_axis_values, y_range=(0, 10), plot_height=275,
    title="Offset Group Bar Chart", toolbar_location=None, tools="")

p.vbar(
    x=dodge('Coordination Number', -0.05, range=p.x_range),
    top='Green', width=0.2, source=src, color="#8DD3C7", legend_label="Green")

p.vbar(
    x=dodge('Coordination Number',  0.0,  range=p.x_range),
    top='Yellow', width=0.2, source=src, color="#FFD92F", legend_label="Yellow")

p.vbar(
    x=dodge('Coordination Number',  0.05, range=p.x_range),
    top='Red', width=0.2, source=src, color="#E15759", legend_label="Red")

p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.legend.location = "top_left"
p.legend.orientation = "horizontal"
p.xaxis.axis_label = "Coordination Number"
p.yaxis.axis_label = "Frequency"

show(p)

这很好地将数据发送到我的服务器,但是当我去获取服务器中的文件时,它总是返回未定义状态。

    const fileChooser = document.getElementById('config-file-upload');
    const file = fileChooser.files[0];
    
    let formData = new FormData();
    formData.append('file', file);

    $.ajax({
        url: baseURL + "upload-doc",
        type: 'POST',
        data: formData,
        processData: false,
        contentType: 'multipart/form-data'
    });

我曾经尝试使用multer之类的库,但是当我尝试访问文件时仍然无法定义

    app.post('/upload-doc', (req, res) => {
        console.log(req.body);
    });

感谢您的帮助。

0 个答案:

没有答案