Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uploadFile() {
- const xhr = new XMLHttpRequest();
- xhr.onreadystatechange = () => {
- if (xhr.readyState === XMLHttpRequest.DONE) {
- _converse.log("Status: " + xhr.status, converse_chat_Strophe.LogLevel.INFO);
- if (xhr.status === 200 || xhr.status === 201) {
- this.save({
- 'upload': _converse.SUCCESS,
- 'oob_url': this.get('get'),
- 'message': this.get('get')
- });
- } else {
- xhr.onerror();
- }
- }
- };
- xhr.upload.addEventListener("progress", evt => {
- if (evt.lengthComputable) {
- this.set('progress', evt.loaded / evt.total);
- }
- }, false);
- xhr.onerror = () => {
- let message;
- if (xhr.responseText) {
- message = __('Sorry, could not succesfully upload your file. Your server’s response: "%1$s"', xhr.responseText);
- } else {
- message = __('Sorry, could not succesfully upload your file.');
- }
- this.save({
- 'type': 'error',
- 'upload': _converse.FAILURE,
- 'message': message,
- 'ephemeral': true
- });
- };
- xhr.open('PUT', this.get('put'), true);
- xhr.setRequestHeader("x-amz-acl",'public-read');//<--
- xhr.setRequestHeader("Content-type", this.file.type);
- xhr.send(this.file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement