FYI:
I couldn't find out why $http
is not working .. even I found strange things according to this topic.
So first I "fetched" the file from html like this:
<input flex="40" type="file" onchange="angular.element(this).scope().$parent.selectAttachment(this)">
becuase I didn't want to create a directive for this testing purpose. The selectAttachment
function simply set the file as a property for my controller.
Then seemingly it was ok, I could read e.g this.attachment.name
or this.attachment.size
, but when I wrote $http.put(url, this.attachment)
I got the signature-mismatch error.
Then I tried the same with XHR as in this tutorial: https://devcenter.heroku.com/articles/s3-upload-node
Never lucky...
Then, as a last resort, I tried to fetch the file by not setting it via angular but const file = document.getElementById('report-attachment').files[0];
and finally it worked for me. Intrestingly, fetching the file with getElementById
AND using $http still not work, neither 1 or 2 3rd party angular uploader I tried, only with XHR o.o
The final "solution" which works for me:
HTML:
<input flex="40" id="report-attachment" type="file">
JS:
const file = document.getElementById('report-attachment').files[0];
const url = r && r.data;
const xhr = new XMLHttpRequest();
xhr.open('PUT', url);
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.debug('success');
} else {
console.error('error');
}
}
};
xhr.send(file);