想請(qǐng)教一下大家,關(guān)于在angularJs中進(jìn)行文件上傳時(shí),上傳路徑該如何定義?比如看到網(wǎng)上有個(gè)例子如下:.directive.js中.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){?? ???? $scope.uploadFile = function(){?? ??? ??? ?debugger;?? ???????? var file = $scope.myFile;?? ???????? console.log('file is ' );?? ???????? console.dir(file);?? ???????? var uploadUrl = "/file";?? ???????? debugger;?? ???????? fileUpload.uploadFileToUrl(file, uploadUrl);?? ???????? debugger;?? ???? };?? ??? ??? ?}]);.service.js中.factory('fileUpload', ['$http', function ($http) {?? ??? ???? var uploadFileToUrl = function(file, uploadUrl){?? ??? ???????? var fd = new FormData();?? ??? ???????? fd.append('file', file);?? ??? ???????? debugger;?? ??? ???????? $http.post(uploadUrl, fd, {?? ??? ???????????? transformRequest: angular.identity,?? ??? ???????????? headers: {'Content-Type': undefined}?? ??? ???????? })?? ??? ???????? .success(function(){?? ??? ??????? ??? ?alert("圖片上傳成功!");?? ??? ???????? })?? ??? ???????? .error(function(){?? ??? ??????? ??? ?alert("error,圖片上傳失??!");?? ??? ???????? });?? ??? ???? };?? ??? ??? ??? ??? ???? return {?? ??? ??? ??? ?uploadFileToUrl : uploadFileToUrl ?? ??? ???? };?? ??? ?}]);項(xiàng)目首頁(yè)請(qǐng)求地址是localhost:3000,但是項(xiàng)目的真實(shí)port是8080。那保存文件的路徑/file是在哪里?
- 1 回答
- 0 關(guān)注
- 6867 瀏覽
添加回答
舉報(bào)
0/150
提交
取消