0

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

1 Answer 1

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);
  })
Sign up to request clarification or add additional context in comments.

3 Comments

Here is the problem I cant access the api,I can only consume
Good thanks men,Am thinking putting it on plunker so will let you know
If this one worked are you able to accept the answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.