gpt4 book ai didi

Angularjs文件上传

转载 作者:行者123 更新时间:2023-12-04 21:16:28 24 4
gpt4 key购买 nike

html

    <form method='POST' enctype='multipart/form-data' name="formName">
<div class="row">
<div class="col-md-6">
<input type="file" style="text-align: left" ng-model="value" class="btn"/>
</div>
<div class="col-md-2">
<input type="submit" value="upload" class="btn btn-info" ng-click="submitFile()"/>
</div>
</div>
</form>

AngularJs
$scope.submitFile = function(){
document.formName.action = 'http://xxx.xxx.xxx.xxx:8000/ww/up?s=' + $rootScope.reply.Sid; //$rootScope.reply.Sid is secession id
document.formName.submit();
};

我正在尝试使用 AngularJs 进行文件上传。这个逻辑会起作用吗?我选择的路径也如下所示。
C:\fakepath\license.txt

这是一个错误吗?

笔记:
我们的 UI 团队能够使用以下代码上传文件。我试图在 AngularJs 中实现同样的目标
<body>
<form method='POST' enctype='multipart/form-data' action="http://xxx.xxx.xx.xxx:xxxx/yyy/yyyyyyyyy?s=3e3646ea-48cc-4342-a388-e0c0d7bbf4e4"/'>
File to upload: <input type=file id='up_file' name=upfile><br>
</body>

最佳答案

你做对了..你只需要改变一些事情就可以让它工作

改变

<form method='POST' enctype='multipart/form-data' name="formName">


<form action="{{action}}" method='POST' enctype='multipart/form-data' name="formName">

在 Controller 中注入(inject) $超时连同 $范围
app.controller('Test', function($scope, $rootScope, $timeout){

$scope.submitFile = function(){
$scope.action = 'http://xxx.xxx.xxx.xxx:8000/ww/up?s=' + $rootScope.reply.Sid;

$timeout(function(){
document.formName.submit();
}, 100);

}

});

使用新数据分配 $scope.action 的操作 .. angularjs 需要更新 dom .. 这就是我们使用 的原因$超时并提交表格

关于Angularjs文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22198227/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com