Project

General

Profile

Actions

CompressPdf #1817

open

Resolving unable to access pdf error for link upload

Added by Ayat Rahman about 1 year ago. Updated about 1 year ago.

Status:
To Do
Priority:
High
Assignee:
Category:
bug
Target version:
Start date:
01/28/2025
Due date:
01/28/2025 (about 15 months late)
% Done:

100%

Estimated time:
6:00 h
Spent time:

Description

Description

Users are encountering an error when trying to upload PDFs via external links. The error occurs due to CORS (Cross-Origin Resource Sharing) restrictions, which block requests to external servers that do not include the Access-Control-Allow-Origin header. This issue prevents users from uploading PDFs from certain links, such as https://tcg.mae.cornell.edu/pubs/Pope_ARFM_94.pdf.


Steps to Reproduce

  1. Go to the link upload feature on the website.
  2. Enter a PDF link from an external server (e.g., https://tcg.mae.cornell.edu/pubs/Pope_ARFM_94.pdf).
  3. Click "Submit."
  4. Observe the error:
    Access to fetch at 'https://tcg.mae.cornell.edu/pubs/Pope_ARFM_94.pdf' from origin 'https://dev.compresspdf.to' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
    

Expected Behavior

Users should be able to upload PDFs from any valid external link without encountering CORS-related errors.


Proposed Solution

Implement a proxy server to handle external PDF requests. The proxy server will:

  1. Fetch the PDF from the external server on behalf of the client.
  2. Forward the PDF to the client, avoiding CORS restrictions.
  3. Validate the PDF (e.g., check file type and size) before allowing the upload.

Tasks

  1. Create a Proxy API Route:

    • Add a new API route (/api/proxy) in the Next.js app to handle external PDF requests.
    • Ensure the route fetches the PDF and forwards it to the client.
  2. Update Link Validation Logic:

    • Modify the validatePdfLink function to use the proxy API route for validation.
  3. Update Link Upload Logic:

    • Modify the handleURLSubmit function to use the proxy API route for fetching the PDF.
  4. Test the Solution:

    • Test with various external PDF links to ensure the CORS issue is resolved.
    • Verify that PDF validation (file type and size) works as expected.
  5. Deploy the Changes:

    • Deploy the updated code to the production environment.

Acceptance Criteria

  • Users can upload PDFs from any external link without encountering CORS errors.
  • The proxy server successfully fetches and forwards PDFs to the client.
  • PDF validation (file type and size) works as expected.
Actions

Also available in: Atom PDF