Unable to proxy multi-part form
Problem
Multiple attempts to proxy multi-part using both the browser and curl. Might be something really small but cannot seem to figure it out. The curl command sends the expect header and the browser does not. However, both do not proxy the request. Might be easier to see the first issue with the curl command and then narrow the issue down for the browser. Curl command curl -v --upload-file ./cam_espn.jpg http://127.0.0.1:3000/todkap%40us.ibm.com/cam_espn5.jpg Output todkapmacbookpro:bluemix_objectstorage_bug todd$ curl -v --upload-file ./cam_espn.jpg http://127.0.0.1:3000/todkap%40us.ibm.com/cam_espn5.jpg - Hostname was NOT found in DNS cache - Trying 127.0.0.1... - Connected to 127.0.0.1 (127.0.0.1) port 3000 (#0) > PUT /todkap%40us.ibm.com/cam_espn5.jpg HTTP/1.1 > User-Agent: curl/7.37.1 > Host: 127.0.0.1:3000 > Accept: _/_ > Content-Length: 197616 > Expect: 100-continue > < HTTP/1.1 100 Continue < HTTP/1.1 100 Continue - We are completely uploaded and fine < HTTP/1.1 404 Not Found < X-Powered-By: Express < SkipProxyWeb: true < X-Content-Type-Options: nosniff < Content-Type: text/html; charset=utf-8 < Content-Length: 46 < Date: Fri, 02 Jan 2015 14:55:39 GMT < Connection: keep-alive < Cannot PUT /todkap%40us.ibm.com/cam_espn5.jpg - Connection #0 to host 127.0.0.1 left intact Node script todkapmacbookpro:bluemix_objectstorage_bug todd$ cat app.js [code block] Server side log Logging inbound request PUT /todkap%40us.ibm.com/c
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix Multi-Part Form Proxying Issue
The 404 Not Found error indicates that the server is unable to locate the specified resource. This could be due to incorrect URL encoding or the server not handling the multipart form data correctly. The curl command is using a PUT request, which may not be supported by the server for the specified endpoint. Additionally, the server may not be configured to handle multipart form uploads properly.
Awaiting Verification
Be the first to verify this fix
- 1
Update Server Endpoint to Handle PUT Requests
Ensure that the server is configured to handle PUT requests for the specified endpoint. If the endpoint is not meant to handle file uploads via PUT, consider using POST instead.
javascriptapp.post('/todkap%40us.ibm.com/:filename', upload.single('file'), (req, res) => { /* handle file upload */ }); - 2
Check URL Encoding
Verify that the URL is correctly encoded. The '@' character in the email address should be encoded as '%40'. Ensure that the filename is also correctly formatted in the request.
javascriptconst encodedEmail = encodeURIComponent('todkap@us.ibm.com'); - 3
Switch to POST Method in Curl Command
Change the curl command to use POST instead of PUT, as this is more commonly used for file uploads.
bashcurl -v -F 'file=@./cam_espn.jpg' http://127.0.0.1:3000/todkap%40us.ibm.com/cam_espn5.jpg - 4
Add Middleware for Multipart Handling
Ensure that the server has middleware like 'multer' configured to handle multipart form data. This is essential for processing file uploads.
javascriptconst multer = require('multer'); const upload = multer({ dest: 'uploads/' }); - 5
Test with Browser and Curl
After making the above changes, test the endpoint using both curl and a browser to ensure that the file uploads successfully.
bashcurl -v -F 'file=@./cam_espn.jpg' http://127.0.0.1:3000/todkap%40us.ibm.com/cam_espn5.jpg
Validation
Confirm that the server responds with a 200 OK status and the file is successfully uploaded to the specified location. Check server logs for any errors and ensure that the file exists in the upload directory.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep