'How to download files from S3 to a custom folder or a network path using boto3

Below is the function to download the files from a S3 Bucket. But the problem is I can't find how to direct those files into a network path instead of downloading into the project folder without having any control over where the files must be downloaded.

import boto3
import config
import os
import win32api

def download_all_objects_in_folder():
 #= boto3.resource('s3')
s3_resource = boto3.resource('s3', aws_access_key_id=config.AWS_BUCKET_KEY, aws_secret_access_key=config.AWS_BUCKET_SECRET_KEY) 
my_bucket = s3_resource.Bucket(config.BUCKET)
# Create the folder logic here
objects = my_bucket.objects.filter(Prefix='Export_20181104/')
for obj in objects:
    path, filename = os.path.split(obj.key)
    my_bucket.download_file(obj.key, filename,"C:\Other")
    #win32api.MessageBox(0, obj.key, 'title')

print("imports completed")

Update: This is the error I am getting when I pass the custom path.

ValueError: Invalid extra_args key 'C', must be one of: ChecksumMode, 
VersionId, SSECustomerAlgorithm, SSECustomerKey, SSECustomerKeyMD5, 
RequestPayer, ExpectedBucketOwner


Solution 1:[1]

There is no difference for Python or the Boto3 SDK where you download your specified S3 object, whether that is a local or network location.

That concern is up to the operating system.

Download to the network location, just as you would download to the local location.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ermiya Eskandary