使用没有后端脚本的Angularjs上传文件(例如PHP,JAVA等)
As I am doing this just for demo, and my backend team yet not started, I want to save my file to the some folder of my project (I don't want to save in database).
因为我这样做只是为了演示,而我的后端团队还没有启动,我想将我的文件保存到我项目的某个文件夹中(我不想保存在数据库中)。
I just want is when I am uploading some file and pressing upload button, that file should copy in perticular folder of project. These all should happend with AngularJS only or JavaScript. (NO ANY BACKEND SCRIPT eg. PHP, JAVA, etc)
我只想要的是当我上传一些文件并按下上传按钮时,该文件应该复制到项目的特定文件夹中。这些都应该只使用AngularJS或JavaScript。 (没有任何支持脚本,例如PHP,JAVA等)
I tried with these given codes, but it is not giving error 404: PATH NOT FOUND for the folder to upload.
我尝试使用这些给定的代码,但它没有给出错误404:找不到要上载的文件夹的路径。
Tried Examples:
myApp.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){
$scope.uploadFile = function(){
var file = $scope.myFile;
console.log('file is ' );
console.dir(file);
var uploadUrl = "/fileUpload";
fileUpload.uploadFileToUrl(file, uploadUrl);
};
}]);
https://jsfiddle.net/JeJenny/ZG9re/
http://jsfiddle.net/danialfarid/maqbzv15/1118/
Please, Give some suggestion.
请提出一些建议。
2 个解决方案
#1
1
In order to POST
to a particular location, you need to have a backend endpoint listening to that location. This is why you're getting a 404, not found.
要POST到特定位置,您需要让后端端点侦听该位置。这就是为什么你得到404,没找到。
The best you can do if you want to demonstrate locally is to make use of the file.Copy()
method to simulate file saving. http://www.java2s.com/Tutorial/JavaScript/0600__MS-JScript/FileCopy.htm
如果要在本地演示,可以做的最好的事情是使用file.Copy()方法来模拟文件保存。 http://www.java2s.com/Tutorial/JavaScript/0600__MS-JScript/FileCopy.htm
更多相关文章
- JS获取文件名的方法
- 使用Jquery Ajax更改按钮的颜色(从外部PHP文件接收颜色)
- jQuery Slimbox没有正确请求文件
- 利用javascript实现遍历xml文件的代码实例
- 使用jQuery导出JSON(外部文件)导入数据的度假输出
- JQuery纯前端导入Excel文件,兼容IE10及IE9版本以下浏览器处理方法
- 根据AngularJS中的条件制作输入类型文件[duplicate]
- 如何使用django从静态文件加载静态文件?
- 没有AJAX的拖放文件上传,在前台同步?