File对象无法上传到服务器在Safari
问题描述:
任务是使在浏览器中的文件,然后上传到服务器上。 我已经创建了blob对象,然后在浏览器中创建了文件对象,然后将其上载到服务器上。File对象无法上传到服务器在Safari
var file = [new File([data],'-Invoice.pdf', {type: 'application/pdf;charset=utf-8;'})];
在safari中成功创建文件,但当我要求上传时,服务器用404 i-e文件未找到错误回复我。 在Chrome/Firefox中完美工作。 在服务器端使用npm模块express-fileupload。 请帮我
答
在浏览器的差异应该不会影响到服务器端上传。在打电话给服务器时,应该仔细检查是否有该文件。
我假设你没有使用自己的文件上传按钮。尝试按照他们的HTML上传指南,它应该工作,虽然我还没有在Safari中测试过。
$scope.upload = function (file) {
console.log(file.length); // if less than 1 or undefined, then your problem is probably in the html. I
Upload.upload({
url: 'upload/url',
data: {file: file, 'username': $scope.username}
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
console.log('Error status: ' + resp.status);
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded/evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};
我想它已经,但问题仍然存在。 –