我正在使用ngf-file-upload模块通过angularjs和laravel上传文件 .
这是我的html倡导者:
<div class="button" ngf-select="profile.uploadFiles($file, $invalidFiles)">Upload on file select</div>
这是我的角度控制器
vm.uploadFiles = function(file) {
if (file) {
file.upload = Upload.upload({
url: 'http://localhost/api/uploadImg',
data: {file: file}
});
}
}
这是我在Laravel中上传的API代码 .
public function uploadImg()
{
$data = Input::file('file');
return $data;
}
我的角应用程序在默认端口上运行9000端口和laravel . 来自angular的请求正在击中建在laravel中的api,但问题是它的网络 . 像 content-type 不是 multipart/form-data
This is the link of danial farid js fiddle
我使用相同的代码,改变与我的api同步,这是在小提琴中提到的 .
奇怪的是,当我给这个小提琴的路径时,它工作正常 . 但它并没有在我的项目本地工作 . 我觉得我的角度方面有些东西是我遗漏的 .
This is the image of param that is send when i am trying to upload file from local project
This is the image of param that is send when i am trying to upload file from fiddle to my api
My Conclusion
代码中没有问题,因为我能够从html文件(不是在我的角度项目中)上传文件,这是我为测试文件上传而创建的,并且它正在运行 .
BUT
当我尝试通过我的项目上传时,它失败了 . 我已经附上 images of my console one case is working one (通过随机文件上传图片),其他是 not working case (我在哪里 uploading file through my project ) .
我不知道接下来要做什么 . 我认为我的角度项目中有一些东西在我的上传过程中造成了障碍 .
1 回答
Interceptors
是的,他们在文件上传中创建了问题,因为我们在拦截器中设置了标头
以及我们在拦截器中设置的默认标头
对于从我们的角度应用程序发出的每个请求都通过拦截器,拦截器正在使用这些头部修改每个请求 . 所以我必须从拦截器中删除此标头 .
Note