简体   繁体   English

将CSV文件从本地导入到EC2

[英]Import csv file from local to EC2

I am working on Django. 我正在使用Django。 I want to get csv file from remote system. 我想从远程系统获取csv文件。 My code is running on ec2. 我的代码在ec2上运行。 I want to import file on ec2 server. 我想在ec2服务器上导入文件。 How I can do from Django. 我如何从Django执行。

def upload(request):
    if request.method == 'POST' and request.FILES['file']:
        file = request.FILES['file']
        fs.save(file.name, file)

    return HttpResponse("status")

It will store the file as tempfile and I can't read this file. 它将文件存储为tempfile,但我无法读取该文件。

You can open files from any given url with urllib. 您可以使用urllib从任何给定的url打开文件。 Example code: 示例代码:

from urllib.request import urlopen    

with urlopen(URL_OF_FILE) as file:

    csv_file = file.read()
    reader = csv.reader(csv_file.decode('utf-8').splitlines())

    for row in reader:
        # Do something

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM