Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Ziedkh
Contributor III
Contributor III

How to upload PDF file (1) and other parameters (2) through POST REST API

Hello community,

I would like to create a REST request with the following parameters int Talend. Which component should I use and how to pass parameters to this component (body)? I have all necessary metadata on an input edge, need to transform somehow to body/string parameter and add definition for file to upload (path on the edge).

0695b00000L1mZ5AAJ.png 

I have used tRestClient :

0695b00000L1maXAAR.png 

0695b00000L1mbfAAB.png 

0695b00000L1mbuAAB.png 

and I used tRest :

0695b00000L1mdHAAR.png 

0695b00000L1mdRAAR.png 

Any Help please

@

xdshi

@richard Hall​ 

Thank you.

Labels (3)
19 Replies
Anonymous
Not applicable

OK, this is going to take some trial and error I'm afraid. First of all, the repository_id and type_id are both form properties, so do not go in the header. They are also both of type integer and not String. We'll ignore the metadata until we get rid of the repository_id error. Can set the repository_id and type_id params to be integers (remove the double quotes) and see what that returns please?

Ziedkh
Contributor III
Contributor III
Author

 

I've already tried that, but the param mehode doesn't allow integer as a values.

0695b00000L2JH4AAN.png

0695b00000L2JHEAA3.png 

Anonymous
Not applicable

I've just noticed something that makes me think part of your problem is caused by something else in your job failing. This image here......

 

0695b00000L2JapAAF.png 

Shows a nullpointerexception that is not necessarily linked to your tRestClient. The URL at the top of the sys out suggests that you have a tRestRequest in this job somewhere. Can you show the whole job and show the whole of the error messages you get in text please?

Ziedkh
Contributor III
Contributor III
Author

here the job,

0695b00000L2WOmAAN.pngFirst I've used tRequest to get file and params,

0695b00000L2WPBAA3.pngas you see here, I've got the file in my local repo through Postman Request:

0695b00000L2WPpAAN.png0695b00000L2WPGAA3.pngAnd then i get the NullPointerException in tRestClient .

 

For me it's the first time that i handle a Post file through an API that why i didn't catch exactly the prob 😟

 

" Démarrage du job WS_GED_POST_TEST a 11:23 30/11/2021.

Endpoint deployed at: http://127.0.0.1:8040/api/v1/documents

[statistics] connecting to socket on port 3394

[statistics] connected

Exception in component tRESTClient_2 (WS_GED_POST_TEST)

java.lang.NullPointerException

at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST.tRESTClient_2Process(WS_GED_POST_TEST.java:3057)

at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST.tRESTRequest_1_LoopProcess(WS_GED_POST_TEST.java:4721)

at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST$RestServiceProviderImpl4TalendJob.processRequest(WS_GED_POST_TEST.java:714)

at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST$RestServiceProviderImpl4TalendJob.Request(WS_GED_POST_TEST.java:813)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179)

at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)

at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:193)

at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:103)

at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)

at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)

at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)

at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)

at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)

at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:247)

at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:79)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)

at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:205)

at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)

at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)

at org.eclipse.jetty.server.Server.handle(Server.java:505)

at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)

at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)

at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)

at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)

at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:698)

at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:804)

at java.lang.Thread.run(Thread.java:748)

[FATAL]: inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST - tRESTClient_2 null

java.lang.NullPointerException

at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST.tRESTClient_2Process(WS_GED_POST_TEST.java:3057)

at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST.tRESTRequest_1_LoopProcess(WS_GED_POST_TEST.java:4721)

at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST$RestServiceProviderImpl4TalendJob.processRequest(WS_GED_POST_TEST.java:714)

at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST$RestServiceProviderImpl4TalendJob.Request(WS_GED_POST_TEST.java:813)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179)

at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)

at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:193)

at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:103)

at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)

at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)

at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)

at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)

at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)

at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:247)

at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:79)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)

at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:205)

at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)

at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)

at org.eclipse.jetty.server.Server.handle(Server.java:505)

at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)

at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)

at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)

at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)

at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:698)

at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:804)

at java.lang.Thread.run(Thread.java:748)"

 

Anonymous
Not applicable

Can you remove all of the other components (maybe create another job) and just add the tRestClient with a tLogRow. Without access to your Job I can't identify what is causing the NullPointerException. You may be able to find this by looking at the code line numbers in the error and looking at the Java. If you can understand Java, this may be quite easy.

 

But to remove any other possible causes for the nullpointerexception, we need to get back to just the tRestClient and the tLogRow (on both response and error outputs).

Ziedkh
Contributor III
Contributor III
Author

 

Here we have only the component in another Job:

 

0695b00000L2WeVAAV.pngand as mentionned here the prob in ligne 1338 which refers to our params in multipart accepter type:

0695b00000L2WekAAF.png0695b00000L2WgHAAV.pngI've changed the Accepter-type to All and as you see it detect the repository_id and the file is as always missing 😞

 

0695b00000L2WgbAAF.png0695b00000L2WggAAF.pngI've even tried to integrate the File in the header and i didn't work either.

0695b00000L2Wh5AAF.png 

I think that with tRest and tRestClient we couldn't pass file as a param .

have you another point of view or proposition please ?

Thanks 🙂

Anonymous
Not applicable

Right, so it appears that you are just missing the file now. This is good. I suspected that the file name would not work. Unfortunately, since I do not have access to this API I cannot try anything out myself. When working with APIs it usually takes a few attempts to get the calls correct.

 

Move the file param back to the parameters and wrap the path to the file in this routine method.....

 

package routines;

 

import java.io.File;

import java.io.IOException;

import java.nio.charset.StandardCharsets;

import java.nio.file.Files;

 

import org.apache.commons.codec.binary.Base64;

 

 

 

public class Base64File {

 

public static String encodeFileToBase64Binary(String filePath) throws IOException {

  byte[] encoded = Base64.encodeBase64(Files.readAllBytes(filePath));

  return new String(encoded, StandardCharsets.UTF_8);

}

}

 

.....this is to provide the contents of the file in Base64 which could be what your API is expecting.

 

What is the name of the software providing the API you are using? Is it something that I might be able to get a copy of so that I can try somethings out? It would make it much easier to be able to examine the errors ad tweak the config for myself.

Ziedkh
Contributor III
Contributor III
Author

 

I don't think that, but i give it a try :

 

0695b00000L2YHTAA3.pngI tried it also through Postman but it didn't work:

0695b00000L2YXHAA3.pngAs I mentionned before the API get a FILE as params

0695b00000L2YYAAA3.png 

 

Anonymous
Not applicable

What software is exposing the API you are trying to send the file to?

Ziedkh
Contributor III
Contributor III
Author

Hello @Richard Hall​  @Xiaodi Shi​ 

 

I have finally make this API.

I have used tFileFetch :

0695b00000LxFpVAAV.png0695b00000LxFpzAAF.pngHere is my notes to close this case :

  • In TFileFetch, we didn’t specify the context-type ( it’s already specified in the component code )
  • We get the responses ( sucess or reject ) from global variables ERROR_MESSAGE and INPUT_STREAM )
  • We get responses with OnComponentOk and OnComponentError
  • We have to put an iterate link before tFileFetch to eliminte loops generated on errors

 

Thank you for your collaboration.

 

zied