我目前正在使用ng-flow执行文件上传.看来,选择文件的默认操作是立即上传.我想覆盖它,以便选择文件并仅在按钮单击时上传.也许我误读了文档,但到目前为止我有以下内容:
<div flow-init="{target: '/upload'}"
flow-files-submitted="$flow.upload()"
flow-file-success="$file.msg = $message">
<input type="file" flow-btn/>
Input OR Other element as upload button
<span class="btn" flow-btn>Upload File</span>
<table>
<tr ng-repeat="file in $flow.files">
<td>{{$index+1}}</td>
<td>{{file.name}}</td>
<td>{{file.msg}}</td>
</tr>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
这似乎工作,我可以看到网络请求出去.我在点击时找到了flow.js上传文件,并尝试按照建议的答案,但$flow
在相应的功能中未定义.
那么,如何使用ng-flow以编程方式上传文件?
我尝试使用 angularjs 和引导程序使用 ng-flow 模块实现个人资料图片上传。在 safari 中它工作正常,但在 chrome 中该请求不起作用。它向我显示“注意:请求尚未完成”
这是一个屏幕截图:
我试图禁用所有 chrome 扩展等,但它仍然无法正常工作。我注意到的另一件事(我不知道它是否与我最初的问题有关)是一个奇怪的按钮边框错位,它似乎也只出现在 chrome 中。
从我的角度来看代码:
<div class="row">
<div class="col-md-12">
<h2 style="text-align: center">edit your profile</h2>
</div>
<div ng-controller="uploadCtrl" flow-init="{singleFile:true}" flow-name="uploader.flow" flow-files-added="processFiles($files)">
<div class="form-group">
<button flow-btn class="btn btn-primary btn-sm" flow-attrs="{accept:'image/*'}">Upload Profile Picture</button>
</div>
<div class="thumbnail" ng-show="$flow.files.length">
<img class="preview" flow-img="$flow.files[0]"/>
</div>
<button class="btn btn-primary btn-sm" ng-show="$flow.files.length" ng-click="save()">save</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
控制器:
angular.module("myController").controller('uploadCtrl', function($scope, profileService) {
$scope.imageStrings = [];
$scope.processFiles = function(files){
angular.forEach(files, function(flowFile, i){
var fileReader = new FileReader();
fileReader.onload = function (event) …
Run Code Online (Sandbox Code Playgroud) 我正在使用ng-flow指令将文件上传到服务器.有没有办法可以使用普通上传而不是ng-flow模块中使用的分块上传?
我最近开始使用升级模块将 AngularJS 应用程序迁移到 Angular 4。
我的 AngularJS 指令之一使用第三方库 ( ngFlow ) 使用XMLHttpRequest.send()
. 在混合模式下运行时,上传在 Chrome 和 Firefox 中都可以正常工作。但是,在 Safari 中,应用程序在上传过程中变得非常缓慢,并且浏览器进程的 CPU 使用率达到 100%。
使用 Safari 网络工具,我看到有很多globalZoneAwareCallback
来自 zone.js的调用。
我的印象是 Angular 区域正在为XMLHttpRequest
上传期间发生的每个进度事件启动更改检测。
我知道我可以使用runOutsideAngular
fromNgZone
来避免这种情况,但我不知道如何在第三方 AngularJS 库中发生异步调用的情况下使用它,或者是否有任何其他解决方案可以解决此问题。