Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Swiip
Contributor
Contributor

How to post a picture with an API (authorization : Bearer token)

Hi

I need to post a picture (.jpg file) using an api with Talend.

  • Maybe i have to use a tRESTClient with the method POST. But if i use this component how to indicate the file to upload ?
  • Maybe i have to use a tFileFetch with the method POST. But if i use this component i can check the box for the authentification (in advanced parameter) but i can see only User and Password. But i have to use a bearer token. How to use the token ?

Thank you very much for your help.

Best regards

Labels (3)
22 Replies
gjeremy1617088143

Hi, use tRestclient with bear token auth , you have to look a the documentation of your api to see example of what you want.

Send me Love and Kudos

Swiip
Contributor
Contributor
Author

Hi

 

Thanks for your help.

 

The documentation :

SetPictureUser

Body: (Form-data)

-         UPN : Identifier is UserPrincipalName, equivalent to email

-         Image (IFormFile of image 400x400)

 

Returns: ResultInfo Item

 

ResultInfo item

·      IsSuccess (Boolean)

·      Message (Text)

 

 

I used this below but if i look the code i have the error on this :

webClient_tRESTClient_3.query("Image" ,"C:\Users\c_acccma\300000052847554_400.jpg");

0695b00000F8tqrAAB.png 

Thanks

 

 

 

 

 

Swiip
Contributor
Contributor
Author

I replaced the path "C:\Users\c_acccma\300000052847554_400.jpg"

by

"C:/Users/c_acccma/300000052847554_400.jpg"

 

It's better but now i have the error :

mai 26, 2021 2:55:13 PM org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass

INFOS: Creating Service {http://www.talend.org/esb/sam/MonitoringService/v1}MonitoringServiceService from class org.talend.esb.sam.monitoringservice.v1.MonitoringService

mai 26, 2021 2:55:15 PM org.apache.cxf.ws.addressing.ContextUtils retrieveMAPs

AVERTISSEMENT: WS-Addressing - failed to retrieve Message Addressing Properties from context

mai 26, 2021 2:55:15 PM org.talend.esb.sam.agent.collector.EventCollector sendEvents

INFOS: Put events(1) to Monitoring Server.

Exception in component tRESTClient_3 (PostPicture)

javax.ws.rs.WebApplicationException: HTTP 400 Bad Request

at prj_mch.postpicture_0_1.PostPicture.tRESTClient_3Process(PostPicture.java:1749)

at prj_mch.postpicture_0_1.PostPicture.runJobInTOS(PostPicture.java:5087)

at prj_mch.postpicture_0_1.PostPicture.main(PostPicture.java:4779)

Swiip
Contributor
Contributor
Author

In fact in Postman i select the file and the type of the field "Image" is a file. But with Talend i indicate the path. So maybe the problem is here.

Swiip
Contributor
Contributor
Author

I don't know how to do this because i have to send 2 fields : an email and the .jpg file. In Postman i can see "form-data" in the body. But how to do this in Talend ?

Thanks for your help.

gjeremy1617088143

Does your request work on postman ? you can try to add the header parameter you have in postman in your trestclient.

Swiip
Contributor
Contributor
Author

The request works on Postman.

I added the same header except Authorization, Postman-Token and User-Agent.

Talend :

0695b00000F97tzAAB.pngPostman :0695b00000F97tkAAB.pngBut i have the error :

0695b00000F97unAAB.png 

 

 

 

gjeremy1617088143

don't use those who have the value calculated when request is sent

for content-type keep multipart but throw the boundary part)

gjeremy1617088143

if you sned data via body you have to set one to send to the trestclient