Forum Discussion
Hi @Sahil,
Here are two expressions, I was not sure because it is array does always will have only one VW that contains ‘F’ in the value.
First expression. Finds all NO or NP that contains ‘F’ in VW field.
$Data.IDOC.A1.filter(e => e.get('VW').contains('F')).map(x => x.get('NO') != null ? x.NO : x.NP)
But I think that the second expression is more correct. This expression finds the first one element in the array that contains ‘F’ in VW, and returns NO if exist or else NP.
$Data.IDOC.A1.find(e => e.get('VW').contains('F')).get('NO', $Data.IDOC.A1.find(e => e.get('VW').contains('F')).get('NP'))
By default this expression return null, and if you want something else you can add second parameter in the get method for default values.
Ex: .get('NP', "Default")
Regards,
Viktor
- bojanvelevski3 months agoValued Contributor
Hi jfpelletier,
The problem is that in the Python script, you're not just sending the file as multi part form data, you're also sending a content, a payload saying {'fileName': 'fileName.jpg'}. You basically send 2 different payloads JSON and Binary (the very image itself). When the multipart reader snap collects your request, it pulls the JSON first:
And that document doesn't have a content-type attached to it, so your next snap, the binary router, is failing.
Basically, your request from Postman is not sending an additional payload to change the name of the target file, that's why it is passing successfully. Just remove the data=payload part of the request in the script and you'll get the same result in the Postman request.
I hope this helps. If not, let us know.
Regards,
Bojan
- jfpelletier3 months agoContributor
Hello bojanvelevski,
Thanks for your reply! There is one part of your reply that I don't really understand, that is if I remove the "data=payload" part of the request, then how can I also supply a JSON payload at the same time as my file?
The payload includes the name we want to give to the returned files in response (the API takes in one file, does some manipulation, then returns another file). Other parameters will eventually be passed via this payload.
Kind regards,
JF
- bojanvelevski3 months agoValued Contributor
How do you send the name via Postman?
- jfpelletier3 months agoContributor
I send the name as text value in a form-data (and the file as a file value in the same form-data)
- bojanvelevski3 months agoValued Contributor
import requests
url = "https://MyURL.com?bearer_token=abc123"
files=[
('file',('fileName.png',open('file.png','rb'),'image/png'))
]
headers = {}response = requests.request("POST", url, headers=headers, files=files)
print(response.text)
Try this. The first argument in the file line should be the target filename you want to use. Let me know if this helps.
Regards,
Bojan