File transfer pdf upload return error 500

I’m having problems with the fileTransfer, when I send an image it accepts sending normally, when sending in pf format it reaches 99 percent of sending and returns error 500, a detail that “taught” the server to understand pdf files. The server expects four parameters: the file’s imputstream, code, description and user email. As I said when sending images works perfectly

What I tried:

I reviewed the server log and when it is an image it accepts the upload when it is pdf it says it did not receive the file (inputstream parameter)

On Server:

   public String salvar(@FormDataParam("file") InputStream inputStream, @FormDataParam("descricao") String descCliente,
   @FormDataParam("code") String cod, @FormDataParam("email") String loginUsuario) throws Exception {

My get file method:

 getFile(){
    this.fileChooser.open().then((fileURL) =>{
      this.filePath.resolveNativePath(fileURL).then((data) => {
        this.file= data
      })
    })
  }

My upload method:

upload(payload){
    console.log(payload)
    
    var filePath = payload.imageURI;
    var filename = filePath.split("/").pop();
    var extencao = filename.split(".").pop();
    let server
    var options : FileUploadOptions;

    
    server = url
    options = {
      fileKey: "file",
      fileName: filename,
      chunkedMode: false,

      headers: {
        Connecection: "close"
      },
      params: {
        code: this.clienteSelecionado.codigo,
        description: payload.descricao,
        email: this.dados.usuario
      }
    }


    return this.fileTransfer.upload(filePath, server, options).then((data) =>{
      let retorno = JSON.parse(data.response)
      console.log(retorno)
      if (retorno.sucesso) {
        this.toastSucesso(retorno.mensagem)
      } else {
        this.toastSucesso(retorno.mensagem)
      }
      console.log()
    }, (error) => {
      console.log(error)
    });
  }

If you don’t get any better answers, try using HttpClient. That file transfer plugin has been obsolete for years now.

1 Like

Thanks. I’ve tried atpe even with http native but I didn’t get successful. I just don’t use httpClient today because I don’t have access to branch servers and then CORS error appears

I’m not sure what this means exactly, but I guess you’re clear on the fact that CORS really needs to be addressed properly on the server side. If you can’t convince whoever manages your backend to do that, then another option would be to route through a proxy that you do manage that handles the CORS issue.

1 Like