This script is designed to upload files from a local directory to a DigitalOcean Space using the Boto3 library. It is configured to handle specific MIME types for .js
and .css
files and ensure the uploaded files are publicly accessible.
- Python 3.x installed on your machine.
- pip (Python package installer).
- DigitalOcean Space credentials (Access Key and Secret Key).
- The following Python packages:
- boto3
- python-magic
-
Clone the repository to your local machine:
git clone <repository-url> cd <repository-directory>
-
Install the required packages:
pip install boto3 python-magic
-
Replace the placeholders in the script with your actual DigitalOcean Space credentials and endpoint URL.
access_key = 'your_access_key' secret_key = 'your_secret_key'
-
Update the
endpoint_url
to match your DigitalOcean Space configuration:endpoint_url='https://your_bucket.nyc3.digitaloceanspaces.com/'
-
Place the files you want to upload in the
./staticfiles/front/video/
directory. -
Run the script:
python upload_script.py
The script will walk through the specified directory, determine the MIME type of each file, and upload it to the DigitalOcean Space. Files with
.js
and.css
extensions will have their MIME types explicitly set totext/javascript
andtext/css
, respectively.
- Walks through the directory
./staticfiles/front/video/
. - Determines the MIME type of each file.
- Uploads the file to the DigitalOcean Space under the
static
bucket, replacing the./staticfiles/
part of the path. - Sets the files to be publicly readable.
- Lists the objects in the
static
bucket. - Prints the response from the DigitalOcean Space.
Here is an example directory structure and how the files will be uploaded:
Local directory structure:
./staticfiles/front/video/ ├── example.js ├── example.css └── example.txt
After running the script, the files will be uploaded to:
static/front/video/example.js static/front/video/example.css static/front/video/example.txt
If you have suggestions for improving this script, feel free to submit a pull request or open an issue.