问题
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
回答1:
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
})
The file will be uploaded as type ArrayBuffer and you can do what you need to on the back end.
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);
})
来源:https://stackoverflow.com/questions/31589856/how-to-upload-file-in-angularjs-frontend