Actions
CompressPdf #1817
openResolving unable to access pdf error for link upload
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¶
- Go to the link upload feature on the website.
- Enter a PDF link from an external server (e.g.,
https://tcg.mae.cornell.edu/pubs/Pope_ARFM_94.pdf). - Click "Submit."
- 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:
- Fetch the PDF from the external server on behalf of the client.
- Forward the PDF to the client, avoiding CORS restrictions.
- Validate the PDF (e.g., check file type and size) before allowing the upload.
Tasks¶
-
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.
- Add a new API route (
-
Update Link Validation Logic:
- Modify the
validatePdfLinkfunction to use the proxy API route for validation.
- Modify the
-
Update Link Upload Logic:
- Modify the
handleURLSubmitfunction to use the proxy API route for fetching the PDF.
- Modify the
-
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.
-
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