Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Erro 500 quando vou fazer o Upload da imagem

Quando vou fazer o upload acontece o seguinte erro:

POST http://localhost:3000/photos/upload 500 (Internal Server Error) core.js:1673 ERROR HttpErrorResponse {headers: HttpHeaders, status: 500, statusText: "Internal Server Error", url: "http://localhost:3000/photos/upload", ok: false, …} error: {message: "Internal server error"} headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} message: "Http failure response for http://localhost:3000/photos/upload: 500 Internal Server Error" name: "HttpErrorResponse" ok: false status: 500 statusText: "Internal Server Error" url: "http://localhost:3000/photos/upload" proto: HttpResponseBase

api:

Valid token received: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwibmFtZSI6ImZsYXZpbyIsImVtYWlsIjoiZmxhdmlvQGFsdXJhcGljLmNvbS5iciIsImlhdCI6MTU3MzUwNzcxNCwiZXhwIjoxNTczNTk0MTE0fQ.7GBzTOK7w762DgLPC7euljzEDv1Awnia6-nGi1cALns Receiving image file upload complete Photo data { description: 'Exemplo', alowComments: 'true' } File info { fieldname: 'imageFile', originalname: 'home.jpg', encoding: '7bit', mimetype: 'image/jpeg', destination: 'uploads/imgs', filename: '87f1c355-02e3-49ce-9ca0-e83ea2607595.jpg', path: 'uploads\imgs\87f1c355-02e3-49ce-9ca0-e83ea2607595.jpg', size: 135773 } { Error: SQLITE_CONSTRAINT: NOT NULL constraint failed: photo.photo_allow_comments errno: 19, code: 'SQLITE_CONSTRAINT' } undefined

Código Photo.Service:

upload(description: string, allowComments: boolean, file: File){

    const formData = new FormData();
formData.append('description', description);
formData.append('alowComments', allowComments ? 'true' : 'false');
formData.append('imageFile', file);

return this.http.post(API + '/photos/upload', formData);
}

PhotoFormComponent:

upload() { const description = this.photoForm.get('description').value; const allowComments = this.photoForm.get('allowComments').value; this.photoService .upload(description, allowComments, this.file) .subscribe(() => this.router.navigate([''])); }

2 respostas

Boa noite, Viviane! Como vai?

Vc poderia compartilhar o seu projeto no github e mandar o link aqui? Assim poderei dar uma olhada no que está acontecendo.

Qualquer coisa é só falar!

Grande abraço e bons estudos, minha aluna!

solução!

Eu baixei o código e substitui os arquivos.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software