How to upload a file in frontularjs frontend
I want to load api data with the following signature, but I want to double check how the data is received. I only used normal modules in angular to download the file, but I want to check how the file was clicked api. I want the file to be a bunch of bytes when it reaches the api, but here I only download the file. Has the internal transfer protocol been converted to bytes?
Note that the file is of type collection of bytes. How to download this
0
source to share
1 answer
I use ng-file-upload for this . Using the Download service, you can call your api like this:
Upload.upload({
url: '/api/uploadFile',
fields: {fileName: 'fileName', fileExt: '.doc'},
file: file
})
The file will be loaded as type ArrayBuffer and you can do what you need on the back.
Here is a snippet to load with FileSaver, js :
$http.post('/api/downloadFile', 'fileName', {responseType: "arraybuffer"}).
success(function(data) {
var blob = new Blob([data], { type: '.doc' });
saveAs(blob, file.fileName);
})
+1
source to share