如何上传angularjs前端文件 [英] how to upload File in angularjs frontend
问题描述
我要上传具有以下签名数据API,但我想仔细检查数据如何received.I已经应用于角度只是普通的模块上传的文件,但我想检查文件如何推到API 。我要的文件是字节的集合,因为它达到API,但我在这里上传是文件。请问内部传输协议,将其更改为字节
I want to Upload a data api with the following signature but I want to double check how the data is received.I have used just ordinary modules in angular to upload the file but I want to check how the file pushed to the api. I want the file to be collection of bytes as it reaches the api but here am uploading the just the file. Does the internal transfer protocol change it to bytes ?
注意到该文件有个字节的集合类型。
我应该如何上传
notice the file has type of collection of bytes. How should I upload that
推荐答案
为此,我使用纳克 - 文件上传。使用上传服务调用您的API是这样的:
For this I use the ng-file-upload. Using the Upload service to call your api like this:
Upload.upload({
url: '/api/uploadFile',
fields: {fileName: 'fileName', fileExt: '.doc'},
file: file
})
该文件将被上传类型 ArrayBuffer 一>,你可以做你需要在后端的东西。
The file will be uploaded as type ArrayBuffer and you can do what you need to on the back end.
下面是使用 FileSaver,JS 下载一个片段:
Here is a snippet for the download using FileSaver,js:
$http.post('/api/downloadFile', 'fileName', {responseType: "arraybuffer"}).
success(function(data) {
var blob = new Blob([data], { type: '.doc' });
saveAs(blob, file.fileName);
})
这篇关于如何上传angularjs前端文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!