I'm trying to make an API request that sends a PDF...
# cfml-general
j
I'm trying to make an API request that sends a PDF file from my lucee web app, and I'm struggling to get it to work properly. I have it working in postman, but keep getting the error "File is not valid or path doesn't exist!" when I try to do it from my app. Can anyone tell me what I'm doing wrong? (posting picture/code in thread)
working Postman API post:
Code:
s
on your cfhttp tag have you tried adding multipart="yes"?
j
Just tried adding multipart=yes and I got the same error. I've tried using the "file" type for cfhttpparam and it gave me the error message "Java heap space"
d
Huge file maybe?
d
in your cffile tag the filefield needs to be the same name of the POST param
your param name is "formfile" and your filefield in cffile is "Text......upload"
j
Thought that may be the case but it's nothing crazy, 1.7MB. I used the same file when I tested with postman and it worked OK. Will try that now Daniel
d
filefield name does not need to be "form.formFile", simply "formFile" would be correct.
s
have you tried with "file" type for cfhttpparam and multipart=yes at the same time?
j
I have, that also gave the "Java heap space" error
d
Or try a smaller file as a test.
s
ok, is that an error from the api you are posting to, or a cf error on your side?
d
Start with small file from Postman. comment everything out except the cffile tag. Get that upload working first - confirm the file is in your destination. Then uncomment the next step and output some debugging info to help yourself.
j
@Scott I believe the java heap space error is on my end, the "file is not valid or path doesn't exist" is coming from the api I'm posting to, it shows up in the filecontent field when I cfdump cfhttp. I'll give it a try with type=file with a super small file and see if I get the same thing
Have already made sure that the file is getting uploaded, everything is working up to the cfhttp tag
Actually I'm not even sure if the java heap space error is on my end. I'm able to upload the file, read it and cfdump it, and the only thing after that is the cfhttp tag
Made some progress - for some reason I was thinking the "file" attribute had to hold the file data, not the path to the file on the server 🤦‍♂️ I have a different issue now - lucee says I can't have have httpparams with types body and file, mixing them isn't allowed. Is there a way around this? I was hoping that adding multipart=true to the cfhttp tag would help but no luck
Got it working using cfhttpparams with types formField and file - multipart=true ended up not being necessary. Thanks for the suggestions fellas
👍🏾 1