I cannot upload two files to the same document in a Manytoone interface

Asked

Viewed 46 times

1

Hey, guys! Good night. So I have an entity called files and another entity called document. A document can have multiple files. I made a file upload module.

The problem I’m facing is that when I upload more than one file to the same document I get a 'not found' return. I am here without knowing where to go. Someone could help me?

MY FILING ENTITY

@Data
@Entity
public class Arquivo {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY )
    private long id;
    
    private @ManyToOne Documento documento;
    
    private String tipoArquivo;
    
    private @Lob byte[] data;
    
    public Arquivo() {}
    
    public Arquivo(Documento documento, String tipoArquivo, byte[] data) {
        this.documento = documento;
        this.tipoArquivo = tipoArquivo;
        this.data = data;
    }
}

MY DOCUMENT ENTITY

@Data
@Entity
public class Documento {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private @ManyToOne Morador morador;

    @NotNull
    @JsonFormat(pattern = "dd/MM/yyyy")
    private LocalDate dataEntrega;
    
    private @Enumerated(EnumType.STRING) TipoDocumento tipoDocumento;

}

MY FILE CONTROLLER WITH UPLOAD METHOD

@ApiOperation(value = "Upload de uma imagem", notes = "Upload de uma nova imagem.")
    @Transactional
    @ResponseStatus(HttpStatus.CREATED)
    @PostMapping("/uploadArquivo")
    public Arquivo uploadArquivo(
            @ApiParam(name = "arquivo", value = "Arquivo que irá ser feito o upload.", required = true)
            @RequestParam("arquivo") MultipartFile arquivo, 
            @ApiParam(name = "documento_id", value = "id do documento.", required = true, type = "long")
            @RequestParam("documento_id") long id) {

        Documento documento = docRepository.findById(id)
                .orElseThrow(() -> new NegocioException("Documento não encontrado."));

            Arquivo arq = null;
            
            try {
                arq = new Arquivo(documento, arquivo.getContentType(), arquivo.getBytes());
            } catch (Exception e) {
                throw new FileStorageException("Não foi possível criar o arquivo. Por favor, tente novamente.", e);
            }

            return repository.save(arq);
        } 

THE COMEBACK I GET IS THIS

{
    "timestamp": "2020-07-29T02:35:19.853+00:00",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/UploadArquivo"
}

1 answer

0


This specific error message is not related to the code or logic of your application. The "not found" message is related to the "path" of your API. You are not calling the right API. You are calling "Uploadfile", the API being "uploadfile"

  • Whoo, bro. I went general kkkkk. Thanks a lot!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.