为什么fs.writeFile在Windows上不起作用

时间:2019-07-17 12:00:07

标签: node.js filesystems

我正在尝试使用节点js fs节点模块将文件写入窗口位置,并在运行时生成路径 下面的代码不起作用

 <form method="post" enctype="multipart/form-data">

        <button type="submit" class="btn btn-success btn-sm" asp-page-handler="SaveChanges">Save Changes</button>
        <button type="submit" class="btn btn-danger btn-sm" asp-page-handler="CloseTest">Abandon Test Run</button>
        <input type="hidden" asp-for="TestRun.TestRunID" />
        <input type="hidden" asp-for="TestRun.TestItemCreatedUser" />
        @*<div>
            <partial name="_TestRowFatContent"/>
        </div>*@

        <div>
            @if (Model.testRowFatContents.Count > 0)
    {
            <h4>Fat Content Test</h4>
            <table class="table">
                <thead>
                    <tr>
                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].TestRowStatus)
                        </th>

                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].TestRowSampleDescription)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].w1EmptyFlask)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].w2ThimbleWeight)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].w3ThimbleLeatherWeight)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].w4LeatherWeight)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].w5FlaskExtractWeight)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].w6ExtractWeight)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].FatContent)
                        </th>
                        @*<th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].TestItemID)
                        </th>*@
                        <th>
                            @Html.DisplayNameFor(model => model.testRowFatContents[0].TestRowSampleID)
                        </th>

                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @for (int i=0; i < Model.testRowFatContents.Count(); i++)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => Model.testRowFatContents[i].TestRowStatus)
                        </td>
                        <td>
                            <input asp-for="@Model.testRowFatContents[i].TestRowSampleDescription" class="form-control" />
                            <input type="hidden" asp-for="@Model.testRowFatContents[i].TestRowID" />

                        </td>
                        <td>
                            <input asp-for="@Model.testRowFatContents[i].w1EmptyFlask" class="form-control" />
                        </td>
                        <td>
                            <input asp-for="@Model.testRowFatContents[i].w2ThimbleWeight" class="form-control" />
                        </td>
                        <td>
                            <input asp-for="@Model.testRowFatContents[i].w3ThimbleLeatherWeight" class="form-control" />
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => @Model.testRowFatContents[i].w4LeatherWeight)
                        </td>
                        <td>
                            <input asp-for="@Model.testRowFatContents[i].w5FlaskExtractWeight" class="form-control" />
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => @Model.testRowFatContents[i].w6ExtractWeight)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => @Model.testRowFatContents[i].FatContent)
                        </td>
                        @*<td>
                            @Html.DisplayFor(modelItem => item.TestItemID)
                        </td>*@
                        <td>
                            @Html.DisplayFor(modelItem => @Model.testRowFatContents[i].TestRowSampleID)
                        </td>

                        @*<td>
                            <a asp-page="./Edit" asp-route-id="@item.TestRowID">Edit</a> |
                            <a asp-page="./Details" asp-route-id="@item.TestRowID">Details</a> |
                            <a asp-page="./Delete" asp-route-id="@item.TestRowID">Delete</a>
                        </td>*@
                    </tr>
}

以下代码有效:

var fs = require('fs');
var path = require('path');
fs.writeFile(path.join(MediaPath,filepath), buffer, { flag: 'w' }, function (err) {
  console.log(err)
});

0 个答案:

没有答案