无法通过WebHDFS向Hadoop传输文件,遇HTTP 307错误求助
Hey there, let's break down what's happening here and how to fix it. That 307 redirect isn't actually an error—it's WebHDFS doing its job! Here's why, and how to complete your file upload:
Why You're Seeing the 307 Redirect
WebHDFS operates in two distinct steps for file uploads:
- You send a
CREATErequest to the NameNode (yourmyip:50070address) to initiate the upload process. - The NameNode responds with a 307 redirect, pointing you to the DataNode where the actual file content should be sent. This is normal behavior—NameNodes only manage metadata, they don't store file content directly.
Step-by-Step Fix
Let's walk through the full process to get your file uploaded successfully:
Re-run your initial CREATE request and capture the
Locationheader
Your original command is correct for the first step:curl -i -X PUT "http://myip:50070/webhdfs/v1/tmp/tempForTest.txt?user.name=hadoop&op=CREATE&overwrite=false&createparent=false&replication=1&permission=777"Look for a line in the response starting with
Location:—this is the DataNode URL you need to send your file content to. It will look similar to this:Location: http://datanode-ip:50075/webhdfs/v1/tmp/tempForTest.txt?user.name=hadoop&op=CREATE&overwrite=false&replication=1&permission=777&namenoderpcaddress=myip:8020&createflag=&createparent=false
Upload your file to the DataNode URL
Use curl's-Tflag to send your local file to the copied Location URL. Replace/path/to/your/local/tempForTest.txtwith the actual path to your file on your machine:curl -i -X PUT -T /path/to/your/local/tempForTest.txt "http://datanode-ip:50075/webhdfs/v1/tmp/tempForTest.txt?user.name=hadoop&op=CREATE&overwrite=false&replication=1&permission=777&namenoderpcaddress=myip:8020&createflag=&createparent=false"
Quick Checks to Avoid Other Issues
- If
overwrite=false, make sure/tmp/tempForTest.txtdoesn't already exist in HDFS—delete it first if it does. createparent=falserequires the/tmpdirectory to already exist in HDFS. Runhdfs dfs -ls /tmpto confirm it's present.- Verify the
hadoopuser has write permissions on the/tmpdirectory in HDFS. You can check this withhdfs dfs -ls /.
That should get your file uploaded without issues!
内容的提问来源于stack exchange,提问作者김태우

