Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

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 ?enter image description here

notice the file has type of collection of bytes. How should I upload that

share|improve this question

1 Answer 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);
  })
share|improve this answer
    
Here is the problem I cant access the api,I can only consume – Dagm Fekadu Jul 24 at 11:45
    
thanks am going to try that and let you know – Dagm Fekadu Jul 25 at 6:32
    
How did you go? – bwobbones Jul 28 at 11:12
    
Good thanks men,Am thinking putting it on plunker so will let you know – Dagm Fekadu Jul 30 at 6:53
    
If this one worked are you able to accept the answer? – bwobbones Aug 6 at 7:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.