Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struggling with Rest API #131

Closed
rubenixnagios opened this issue May 5, 2023 · 8 comments
Closed

Struggling with Rest API #131

rubenixnagios opened this issue May 5, 2023 · 8 comments
Labels
question Further information is requested

Comments

@rubenixnagios
Copy link
Contributor

Hello there, first of all, congrats for such a nice work.

Since I can do a curl to rest api im testing if I can remove password from there; it works well from web ui but as I have lots of files with password I would like to use the API and make a script to remove passwords from all files.
Im not going deep in the script here, but I post the api call:

curl -X 'POST' \
  'http://192.168.2.43:8087/remove-password?password=actualpdfpassword' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'fileInput=/share/Container/pdf/07.pdf;type=application/pdf' \
  -o '/share/Container/pdf/NO_PASS.pdf'

it creates a 0Kb NO_PASS.pdf file

here the command from my actual instance: http://192.168.2.43:8087/swagger-ui/index.html

curl -X 'POST' \
  'http://192.168.2.43:8087/remove-password?password=actualpdfpassword' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'fileInput=@02.PDF;type=application/pdf'

what Im doing wrong here? any suggestion?
Running Stirling-PDF from docker BTW

Thanks so much in advance!

@Frooodle
Copy link
Member

Frooodle commented May 5, 2023

Don't you need the @ after file input?
Like just to copy a example someone else posted in issues

curl -X 'POST' \ 'http://192.168.102.134:8083/remove-pages?pagesToDelete=2%2C4' \
-H 'accept: /' \ > -H 'Content-Type: multipart/form-data' \
-F 'fileInput=@/share/Public/Escape_Fitness_Deck_2_0.pdf;type=application/pdf' \
-o '/share/Public/Escape_Fitness_Deck_2_0-NEW.pdf'

It has the -F 'fileInput=@/dir

@rubenixnagios
Copy link
Contributor Author

tried that already, with the '@' I get a 3Kb file, it contains:

<!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> Invalid character found in the request target [&#47;remove-password?password=&quot;13195828&quot; ]. The valid characters are defined in RFC 7230 and RFC 3986</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: Invalid character found in the request target [&#47;remove-password?password=&quot;13195828&quot; ]. The valid characters are defined in RFC 7230 and RFC 3986 org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:482) org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:263) org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:894) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741) org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.base&#47;java.lang.Thread.run(Thread.java:833) </pre><p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p><hr class="line" /><h3>Apache Tomcat/10.1.8</h3></body></html>

seen that example already, Im on the paperless-ngx track too (he posted there as well....) small world

@Frooodle Frooodle added the question Further information is requested label May 5, 2023
@Frooodle
Copy link
Member

Frooodle commented May 5, 2023

I think that you need the @ but some invalid characters i guess.. hmmm
"the full stack trace of the root cause is available in the server logs"
can you check docker logs for this?

also according to logs you are putting the passwork in quotes, i dont think it accepts quotes via URL parameters

@Frooodle
Copy link
Member

Frooodle commented May 5, 2023

have you tried to replicate this POST using postman or something to make sure it works as well?
I recommend using postman and hitting its "Code" button to directly convert it to curl

@Frooodle
Copy link
Member

Frooodle commented May 5, 2023

Doing it that way gives me the output like this

curl --location 'localhost:8080/remove-pages'
--form 'fileInput=@"/C:/Users/systo/Downloads/a%E5%A4%A7_rotated.pdf"'
--form 'pagesToDelete="1"'

which might work better for your more unique passwords with special characters rather that using direct URL encoding

@rubenixnagios
Copy link
Contributor Author

will try as soon as i get back home thanks for your efforts, will post in this issue as soon as I can, daughter duties now 😅

@rubenixnagios
Copy link
Contributor Author

I think that you need the @ but some invalid characters i guess.. hmmm
"the full stack trace of the root cause is available in the server logs"
can you check docker logs for this?

also according to logs you are putting the passwork in quotes, i dont think it accepts quotes via URL parameters

i think in docker logs i get what i posted before (file contents)

will post back after checking logs!

thanks again!

@rubenixnagios
Copy link
Contributor Author

Doing it that way gives me the output like this

curl --location 'localhost:8080/remove-pages' --form 'fileInput=@"/C:/Users/systo/Downloads/a%E5%A4%A7_rotated.pdf"' --form 'pagesToDelete="1"'

which might work better for your more unique passwords with special characters rather that using direct URL encoding

indeed that was it, here the final liner:

curl --location '192.168.2.43:8087/remove-password' --form 'fileInput=@"/mypath/myfile.pdf"' --form 'password="pdf_password"' --output '/mypath/myfile_no_password.pdf'

Thanks so much!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants