Ao realizar a atividade 11 da aula 01 do terceiro módulo do curso de Angular me deparei com o seguinte erro:
POST http://localhost:3000/photos/upload 401 (Unauthorized)
Isso acontece quando tento realizar o upload da imagem.
photo-form.component
import { PhotoService } from './../photo/photo.service';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
// tslint:disable-next-line:component-selector
selector: 'ap-photo-form',
templateUrl: './photo-form.component.html',
styleUrls: ['./photo-form.component.css']
})
export class PhotoFormComponent implements OnInit {
photoForm: FormGroup;
file: File;
constructor(
private formBuilder: FormBuilder,
private photoService: PhotoService,
private router: Router
) { }
ngOnInit() {
this.photoForm = this.formBuilder.group({
file: ['', Validators.required],
description: ['', Validators.maxLength(300)],
allowComents: [true]
});
}
upload() {
const description = this.photoForm.get('description').value;
const allowComents = this.photoForm.get('allowComents').value;
this.photoService
.upload(description, allowComents, this.file)
.subscribe(() => this.router.navigate(['']));
}
}
photo.component
import { Component, Input } from '@angular/core';
const CLOUD = 'http://localhost:3000/imgs/';
@Component({
selector: 'ap-photo',
templateUrl: 'photo.component.html'
})
export class PhotoComponent {
private _url = '';
@Input() description = '';
@Input() set url(url: string) {
if (!url.startsWith('data')) {
this._url = CLOUD + url;
} else {
this._url = url;
}
}
get url() {
return this._url;
}
}
Por que não esta autorizando? Poderiam me ajudar?