上传html文件成功但403,错误403当我尝试上传文件(图片)到服务器

我想创建服务器上传图像和填写json的形式。我已经尝试了许多代码和插件下载到服务器,但我总是得到403错误。我的错误是什么?我只使用没有后端的jQuery或AngularJs。这是一个链接:http://salegid.com/dist/最后一个变体:错误403当我尝试上传文件(图片)到服务器

HTML

Image preview...

Image dataURI:

{{uploadme}}

upload image

JS

var app = angular.module('myApp', [

'ngResource',

'ngRoute'

])

.config(['$routeProvider', function ($routeProvider) {

$routeProvider

.when('/', {

templateUrl: 'index.html',

controller: 'MyController',

})

.otherwise({

redirectTo: '/'

});

}])

.controller('MyController', ['$scope', '$http', function($scope, $http) {

//the image

$scope.uploadme;

$scope.uploadImage = function() {

var fd = new FormData();

var imgBlob = dataURItoBlob($scope.uploadme);

fd.append('file', imgBlob);

$http.post(

'imageURL',

fd, {

transformRequest: angular.identity,

headers: {

'Content-Type': undefined

}

}

)

.success(function(response) {

console.log('success', response);

})

.error(function(response) {

console.log('error', response);

});

};

//you need this function to convert the dataURI

function dataURItoBlob(dataURI) {

var binary = atob(dataURI.split(',')[1]);

var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];

var array = [];

for (var i = 0; i < binary.length; i++) {

array.push(binary.charCodeAt(i));

}

return new Blob([new Uint8Array(array)], {

type: mimeString

});

};

}])

.directive('fileread', [

function() {

return {

scope: {

fileread: '='

},

link: function(scope, element, attributes) {

element.bind('change', function(changeEvent) {

var reader = new FileReader();

reader.onload = function(loadEvent) {

scope.$apply(function() {

scope.fileread = loadEvent.target.result;

});

}

reader.readAsDataURL(changeEvent.target.files[0]);

});

}

}

}

]);

你能不能帮我,因为我卡住了。非常感谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值