Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- handleCommit() {
- if (this.state.files.length === 0) {
- this.setState({
- openDlgImagesZero: true,
- });
- return false;
- }
- this.setState({ openSend: true });
- let link = "";
- let files = this.state.files.length;
- let idPropaganda = this.state.commit;
- let textInfo = this.state.textInfo;
- let ctx = this.context;
- if (this.state.files !== null) {
- let fileUploadRef = firebase.storage().ref();
- for (let i = 0; i < this.state.files.length; ++i) {
- let BASE64_MARKER = ';base64,';
- if (this.state.files[i].img.indexOf(BASE64_MARKER) === -1) {
- let parts = this.state.files[i].img.split(',');
- let contentType = parts[0].split(':')[1];
- let raw = decodeURIComponent(parts[1]);
- this.state.files[i].img = new Blob([raw], { type: contentType });
- } else {
- let parts = this.state.files[i].img.split(BASE64_MARKER);
- let contentType = parts[0].split(':')[1];
- let raw = window.atob(parts[1]);
- let rawLength = raw.length;
- let uInt8Array = new Uint8Array(rawLength);
- for (let i = 0; i < rawLength; ++i) {
- uInt8Array[i] = raw.charCodeAt(i);
- }
- this.state.files[i].img = new Blob([uInt8Array], { type: contentType });
- }
- let thumb = this.state.filesThumb[i].img;
- let name = new Date().toISOString().slice(0, 19).replace('T', ' ') + "-" + [i] + ".jpg";
- let fileNameSave = Util.toHex(name);
- this.state.files[i].img.lastModifiedDate = new Date();
- let metadata = { contentType: 'image/jpeg' };
- let uploadTask = fileUploadRef.child('images/agencias/' + window._agencia + '/' + fileNameSave).put(this.state.files[i].img, metadata);
- uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
- function (snapshot) { }, function (error) {
- switch (error.code) {
- case 'storage/unauthorized':
- //
- break;
- case 'storage/canceled':
- //
- break;
- case 'storage/unknown':
- //
- break;
- }
- }, function () {
- let downloadURL = uploadTask.snapshot.downloadURL;
- DataPP._comitarPropaganda(idPropaganda, textInfo, downloadURL, thumb,
- function (response) {
- ctx.router.push('/propagandas?status=' + 4);
- }.bind(this));
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement