Python fetches remote files for real filenames

Source: Internet
Author: User

Download the remote file with Urllib and dump it to the HDFS server, when it is downloaded, it does not necessarily include the file name and needs to be obtained from the connection information.

1     file_url = request.form.get (' File_url ') 2     fo = urllib.urlopen (file_url) 3     blob = fo.read () 4< C7/>file_size = len (BLOB) 5     if Fo.info (). Has_key (' content-disposition '): 6         file_name = Fo.info () [' Content-disposition '].split (' filename= ') [1] 7 file_name = file_name.replace (' "', '). Replace (" ' "," ") 8 print '-in header ' 9 else: file_name= os.path.basename (File_url) one by one file_ext = Get_file_ext (file_name . Lower ()) Remark = Request.form.get ("Remark", "') 14 # stored in HDFs        

Python fetches remote files for real filenames

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.