Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从python在AWS服务器中上载多个文件_Python_Amazon Web Services_Amazon S3 - Fatal编程技术网

如何从python在AWS服务器中上载多个文件

如何从python在AWS服务器中上载多个文件,python,amazon-web-services,amazon-s3,Python,Amazon Web Services,Amazon S3,我正在aws和DB中上载单个文件,但现在如何在aws和我的DB中上载多个文件 下面是单文件上传的代码 def upload_to_s3(filedata,folder_path): s3 = boto3.client('s3', aws_access_key_id=settings.S3_BUCKET_BUCKET_AccessKeyId, aws_secret_access_key=settings.S3_BUCKET_BUCKET_Secr

我正在aws和DB中上载单个文件,但现在如何在aws和我的DB中上载多个文件 下面是单文件上传的代码

def upload_to_s3(filedata,folder_path):
    s3 = boto3.client('s3', aws_access_key_id=settings.S3_BUCKET_BUCKET_AccessKeyId,
                      aws_secret_access_key=settings.S3_BUCKET_BUCKET_SecretAccessKey)

    try:
        filename = filedata.name
        file_name, extension = splitext(filename)
        now = datetime.datetime.now()
        timestamp = int(datetime.datetime.timestamp(now))
        curntfilename = file_name + str(timestamp) + extension
        isexist = False
        for key in s3.list_objects(Bucket=settings.S3_BUCKET_BUCKET_NAME)['Contents']:

            folder = key['Key']
            if folder == (folder_path):
                isexist = True
                data = s3.upload_fileobj(filedata, settings.S3_BUCKET_BUCKET_NAME, '%s/%s' % (folder_path, curntfilename))
                return HttpResponse(json.dumps(data))
        if isexist == False:
            s3.upload_fileobj(filedata, settings.S3_BUCKET_BUCKET_NAME, '%s/%s' % (folder_path , curntfilename))

        print("Upload Successful")
        return curntfilename
    except FileNotFoundError:
        print("The file was not found")
        return False
    except NoCredentialsError:
        print("Credentials not available")
        return False


def upload_to_aws(filedata,filename,timestamp,company_id,folder_id,size,status,created_by,folder_path):
    s3 = boto3.client('s3', aws_access_key_id=settings.S3_BUCKET_BUCKET_AccessKeyId,
                      aws_secret_access_key=settings.S3_BUCKET_BUCKET_SecretAccessKey)

    try:
        #file_name, extension = splitext(filename)
        curntfilename = filename      #file_name + str(timestamp) + extension
        isexist = False
        for key in s3.list_objects(Bucket=settings.S3_BUCKET_BUCKET_NAME)['Contents']:

            folder = key['Key']
            if folder == (folder_path):
                isexist = True
                data = s3.upload_fileobj(filedata, settings.S3_BUCKET_BUCKET_NAME, '%s/%s' % (folder_path, curntfilename))
                uploadprofile(curntfilename,company_id,folder_id,size,status,created_by)
                return HttpResponse(json.dumps(data))
        if isexist == False:
            s3.upload_fileobj(filedata, settings.S3_BUCKET_BUCKET_NAME, '%s/%s' % (folder_path , curntfilename))
            uploadprofile(curntfilename, company_id, folder_id, size, status, created_by)
        print("Upload Successful")
        return True
    except FileNotFoundError:
        print("The file was not found")
        return False

当前代码有什么问题?hi@Marcin当前代码正常工作,现在我想上传多个文件,当前代码也适用于多个文件上传?