<input type="file" id="file-id" name="file_name" onchange="theimage();">

这是我的上传按钮。

<input type="text" name="file_path" id="file-path">

这是一个文本字段,我必须在其中显示文件的完整路径。

function theimage(){
 var filename = document.getElementById('file-id').value;
 document.getElementById('file-path').value = filename;
 alert(filename);
}

这是解决我的问题的JavaScript。但在警报值给我

C:\fakepath\test.csv 

Mozilla给了我:

test.csv

但我想要本地完全限定文件路径。如何解决这个问题?

如果这是由于浏览器安全问题,那么应该采取什么替代方法来做到这一点?

我想从第一个中间件传递一些变量到另一个中间件,我试着这样做,但有“req。有些变量是一个给定的‘未定义’”。


//app.js
..
app.get('/someurl/', middleware1, middleware2)
...

////middleware1
...
some conditions
...
res.somevariable = variable1;
next();
...

////middleware2
...
some conditions
...
variable = req.somevariable;
...

如何获得文件的完整路径,同时选择文件使用<input type= ' file ' >

<input type="file" id="fileUpload">
<script type="text/javascript">
function getFilePath(){
     $('input[type=file]').change(function () {
         var filePath=$('#fileUpload').val(); 
     });
}
</script>

但是filePath var只包含所选文件的名称,而不是完整的路径。 我在网上搜索了一下,但似乎出于安全原因,浏览器(FF,chrome)只给出了文件的名称。 是否有其他方法获得所选文件的完整路径?

我们正在使用REST API开发服务器,它接受和响应JSON。问题是,如果您需要将图像从客户端上传到服务器。

注意:我也在谈论一个用例,其中实体(用户)可以有多个文件(carPhoto, licensePhoto),也有其他属性(名称,电子邮件……),但当你创建新用户时,你不发送这些图像,它们是在注册过程之后添加的。


我知道这些解决方案,但每一个都有一些缺陷

1. 使用multipart/form-data代替JSON

好:POST和PUT请求尽可能的RESTful,它们可以包含文本输入和文件。

缺点:它不再是JSON,相比multipart/form-data更容易测试、调试等

2. 允许更新单独的文件

创建新用户的POST请求不允许添加图像(这在我们的用例中是可以的,我在开始时说过),上传图片是通过PUT请求作为multipart/form-data来完成的,例如/users/4/carPhoto

好的:一切(除了文件上传本身)都保留在JSON中,很容易测试和调试(你可以记录完整的JSON请求,而不用担心它们的长度)

缺点:它不是直观的,你不能POST或PUT实体的所有变量,同时这个地址/users/4/carPhoto可以被认为是一个集合(REST API的标准用例看起来像这个/users/4/出货量)。通常你不能(也不想)GET/PUT实体的每个变量,例如users/4/name。您可以在用户/4处使用get获取名称并使用PUT更改名称。如果在id后面有东西,它通常是另一个集合,比如users/4/reviews

3.使用Base64

将其作为JSON发送,但使用Base64编码文件。

good:与第一个解决方案一样,它是尽可能RESTful的服务。

缺点:同样,测试和调试是非常糟糕的(身体可以有兆字节的数据),有增加的大小和处理时间-客户端和服务器


我很想用解不。但它也有它的缺点……谁能给我一个更好的“什么是最好的”解决方案?

我的目标是使基于rest的服务包含尽可能多的标准,同时我希望使它尽可能简单。

在使用JavaScript上传文件之前,有什么方法可以检查文件大小?

我只是希望左边有流动文本,右边有一个帮助框。

帮助框应该一直延伸到底部。

如果你拿出下面的外部StackPanel,它工作得很好。

但由于布局的原因(我动态插入UserControls),我需要有包装StackPanel。

我如何让GroupBox扩展到StackPanel的底部,正如你所看到的,我已经尝试过了:

VerticalAlignment =“伸展” VerticalContentAlignment =“伸展” 高地=“Auto”

XAML:

<Window x:Class="TestDynamic033.Test3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test3" Height="300" Width="600">
    <StackPanel 
        VerticalAlignment="Stretch" 
        Height="Auto">

        <DockPanel 
            HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" 
            Height="Auto" 
            Margin="10">

            <GroupBox 
                DockPanel.Dock="Right" 
                Header="Help" 
                Width="100" 
                Background="Beige" 
                VerticalAlignment="Stretch" 
                VerticalContentAlignment="Stretch" 
                Height="Auto">
                <TextBlock Text="This is the help that is available on the news screen." TextWrapping="Wrap" />
            </GroupBox>

            <StackPanel DockPanel.Dock="Left" Margin="10" Width="Auto" HorizontalAlignment="Stretch">
                <TextBlock Text="Here is the news that should wrap around." TextWrapping="Wrap"/>
            </StackPanel>

        </DockPanel>
    </StackPanel>
</Window>

答:

谢谢马克,使用DockPanel而不是StackPanel清除它。总的来说,我发现自己现在越来越多地使用DockPanel来进行WPF布局,下面是固定的XAML:

<Window x:Class="TestDynamic033.Test3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test3" Height="300" Width="600" MinWidth="500" MinHeight="200">
    <DockPanel 
        VerticalAlignment="Stretch" 
        Height="Auto">

        <DockPanel 
            HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" 
            Height="Auto" 
            MinWidth="400"
            Margin="10">

            <GroupBox 
                DockPanel.Dock="Right" 
                Header="Help" 
                Width="100" 
                VerticalAlignment="Stretch" 
                VerticalContentAlignment="Stretch" 
                Height="Auto">
                <Border CornerRadius="3" Background="Beige">
                    <TextBlock Text="This is the help that is available on the news screen." TextWrapping="Wrap" 

                Padding="5"/>
                </Border>
            </GroupBox>

            <StackPanel DockPanel.Dock="Left" Margin="10" Width="Auto" HorizontalAlignment="Stretch">
                <TextBlock Text="Here is the news that should wrap around." TextWrapping="Wrap"/>
            </StackPanel>

        </DockPanel>
    </DockPanel>
</Window>

微软现在拥有。net Core、。net Framework和Xamarin (Mono)。

这里似乎有很多重叠。这些类型的。net平台有什么不同?什么时候我应该选择在我的项目中使用。net Core,而不是。net Framework或Xamarin?

假设我们有两个堆栈,没有其他临时变量。

是否有可能“构造”一个队列数据结构只使用两个堆栈?

我想使用cURL不仅在HTTP POST中发送数据参数,而且还上传具有特定表单名称的文件。我该怎么做呢?

HTTP Post参数:

Userid = 12345 filecomment =这是一个映像文件

文件上传: 文件位置= /home/user1/Desktop/test.jpg file = image的表单名称(对应PHP端$_FILES['image'])

我认为cURL命令的一部分如下所示:

curl -d "userid=1&filecomment=This is an image file" --data-binary @"/home/user1/Desktop/test.jpg" localhost/uploader.php

我遇到的问题如下:

Notice: Undefined index: image in /var/www/uploader.php

问题是我使用$_FILES['image']在PHP脚本中拾取文件。

如何相应地调整cURL命令?