我正在尝试使用包含其他表单数据的ng-file-upload提交表单。当文件需要时,我让它工作正常,但现在客户端希望文件上传是可选的。我修改了PHP服务以接受新数据,并且工作正常。
当没有文件附加到表单时,问题是显示成功消息。服务接收和处理数据很好,但现在我无法表明提交成功。
我真的不想在这一点上换档,我喜欢ng-file-upload的预览功能。我尝试在ng-show指令中更改checked变量以获取成功消息,并在$http
函数中设置它,但这不起作用。
我唯一能想到的是根据文件输入是否存在来分支代码,如果不存在则通过常规app.controller('adController', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
//$scope.text = "Is this working?";
$scope.ad = {};
$scope.isSaving = false; // disables fieldset to prevent accidental double-click submissions
$scope.successful_post = false;
$scope.errorClass = function(el) {
var s = $scope.adApplicationForm[el];
return (s.$invalid && s.$dirty) ? "has-error" : "";
};
$scope.submitForm = function(valid) {
console.log("Form Submitted" + valid)
return valid;
};
$scope.uploadPic = function(file) {
$scope.isSaving = true;
file.upload = Upload.upload({
url: 'php/upload_ad.php',
data: {ad: $scope.ad, file: file},
});
file.upload.then(function (response) { // success
$timeout(function () {
file.result = response.data;
});
$scope.isSaving = false;
$scope.successful_post = true;
}, function (response) {
if (response.status > 0)
$scope.errorMsg = response.status + ': ' + response.data;
}, function (evt) {
// Math.min is to fix IE which reports 200% sometimes
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
});
};
}]);
发送,但是有更好的方法吗?
这是我的控制器代码:
@SpringBootApplication
public class MQTTApiApplication {
public static void main(String[] args) {
SpringApplication.run(MQTTApiApplication.class, args);
}
@Bean
public IntegrationFlow mqttinFlow(MqttMessageHandler handler) {
return IntegrationFlows
.from(mqttInbound())
.handle(handler).get();
}
}
感谢您的帮助。