0% found this document useful (0 votes)
8 views4 pages

Automated File Upload System in Python

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Automated File Upload System in Python

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assessment Task: Automated File Upload

System with Notifications


Project Overview

Develop a Python-based system that monitors a specified folder for new files,
uploads them to a server, and displays a desktop notification upon successful
upload. The system should run automatically at system startup.

Payment

An amount of 1000 INR will be provided if the project works fine.

Deliverables

1. Python Script: The core script that handles folder monitoring, file
uploading, and notifications.
2. Executable File: A standalone executable created using PyInstaller.
3. Auto Start Configuration: Instructions and scripts to ensure the
program runs at system startup.
4. README: Detailed setup and usage instructions.
5. Demo: A demonstration of the system in action.

Technical Approach

1. Install Required Libraries:

pip install watchdog requests plyer pyinstaller

2. Python Script: Create a script named file_monitor.py.

import os
import time
import requests
from [Link] import Observer
from [Link] import FileSystemEventHandler
from plyer import notification

class FileUploadHandler(FileSystemEventHandler):
def __init__(self, upload_url):
self.upload_url = upload_url

def on_created(self, event):


if not event.is_directory:
self.upload_file(event.src_path)
def upload_file(self, file_path):
try:
with open(file_path, 'rb') as f:
response = [Link](self.upload_url,
files={'file': f})
if response.status_code == 200:
[Link](
title='File Uploaded',
message=f'{[Link](file_path)}
uploaded successfully',
timeout=5
)
else:
[Link](
title='Upload Failed',
message=f'Failed to upload
{[Link](file_path)}',
timeout=5
)
except Exception as e:
[Link](
title='Error',
message=str(e),
timeout=5
)

def main():
folder_to_monitor = '/path/to/folder'
upload_url = '[Link]

event_handler = FileUploadHandler(upload_url)
observer = Observer()
[Link](event_handler, path=folder_to_monitor,
recursive=False)
[Link]()

try:
while True:
[Link](1)
except KeyboardInterrupt:
[Link]()
[Link]()

if __name__ == "__main__":
main()
3. Create Executable Using PyInstaller:

pyinstaller --onefile file_monitor.py

4. Auto Start Configuration:

For Windows:

◦ Create a shortcut of the executable and place it in the Startup


folder (shell:startup in Run dialog).

For macOS/Linux:

◦ Create a cron job or systemd service to run the executable at


startup.

5. README:

◦ Provide detailed instructions for setting up the environment,


running the script, and configuring auto-start.

# Automated File Upload System

## Setup Instructions

### Prerequisites
- Python 3.x
- Required libraries: `watchdog`, `requests`, `plyer`,
`pyinstaller`

### Installation
1. Install the required libraries:
```bash
pip install watchdog requests plyer pyinstaller

1. Create the executable:

pyinstaller --onefile file_monitor.py

2. Configure auto-start:

▪ Windows: Place the executable’s shortcut in the Startup


folder.
▪ macOS/Linux: Set up a cron job or systemd service.

Running the System

◦ Execute the generated file_monitor.exe (Windows) or


file_monitor (macOS/Linux).
Notes
◦ Ensure the upload URL and folder path are correctly configured in
the script.
◦ The script handles errors and displays notifications accordingly.
```

6. Demo:

◦ Record a short video demonstrating the system in action: adding a


file to the monitored folder, uploading to the server, and receiving
the notification.

Payment Terms

• The system should be thoroughly tested and demonstrated to be


working as specified.
• An amount of 1000 INR will be provided upon successful completion
and verification of the project.

Common questions

Powered by AI

The README document provides essential setup and usage instructions to guide users through the installation and operation of the system. It includes prerequisites such as necessary Python libraries, installation steps, and details on configuring the environment. The README explains how to compile the Python script into an executable and configure the system to run at startup. Its significance lies in enabling even non-technical users to set up and use the system effectively, ensuring wider adoption and reducing setup time and potential errors .

Exceptions in the file uploading process are handled using try-except blocks in the upload_file method of the FileUploadHandler class. If an exception occurs during the file upload process, it is caught in the except block, and a notification is sent to the user using the Plyer notification module. This notification contains the error message, informing the user of the failure in the uploading process .

PyInstaller is used to convert the Python script into a standalone executable file. This conversion allows the deployment of the script without requiring users to have a Python environment set up on their systems. It bundles the script and all its dependencies into one file, making the distribution process straightforward and making the application accessible to non-technical users. This facilitates better portability and ease of use since users can execute the program as they would any native application .

The main components required are a Python script, necessary libraries, an executable file, and auto-start configuration. The Python script monitors a specified folder for new files using the Watchdog library, uploads them to a server using the Requests library, and displays desktop notifications with the Plyer library upon successful upload. The script is converted into an executable file using PyInstaller, which allows it to run independently of the Python environment. For auto-start configuration, in Windows, a shortcut of the executable is placed in the Startup folder, and in macOS/Linux, a cron job or systemd service is set up to execute the file at startup. This configuration ensures that the system runs automatically and performs its tasks efficiently .

The technical approach uses the Watchdog library to monitor file changes. This library listens for file system events and triggers an event handler when files are created, modified, or deleted in the monitored directory. The benefits of using Watchdog include its ease of use and real-time monitoring capability, which is crucial for timely uploads. However, limitations might include resource usage overhead, particularly in directories with high file change volumes, and potential platform dependency issues, though it supports most operating systems .

To handle scalability for multiple folders, the program can be modified to create multiple instances of the Observer and FileUploadHandler classes, each configured for different folders. The main function would need to initialize and start an Observer for each folder path. This design requires additional threads or processes to manage simultaneous monitoring and uploading efficiently. Resources should be managed carefully to avoid bottlenecks, ensuring each observer only triggers uploads for its assigned folder .

The FileUploadHandler class extends the FileSystemEventHandler class from Watchdog. It is initialized with an upload URL. On detecting file creation, the on_created method triggers the upload_file method, which attempts to upload the file to the specified server using HTTP POST via the Requests library. It then checks the response status code; if 200, it uses the Plyer library to notify the user of a successful upload. If any errors occur, it catches them and notifies the user of the error .

Using desktop notifications to convey success and error messages is effective for immediate user feedback, as it allows users to know the status of file uploads in real-time. Notifications ensure users are promptly informed of both successful actions and issues that need attention. However, potential drawbacks include the possibility of notification overload if too frequent, which might desensitize users to alert messages. Additionally, in environments where notifications are disabled or go unnoticed, users may not receive timely information, risking error resolution delays .

The payment terms specify that an amount of 1000 INR is provided upon verification of successful project completion. Successful completion involves the system functioning as specified, including the ability to monitor folders, upload files, and provide notifications reliably. A demonstration, possibly in the form of a recorded video, is needed to verify that all components of the system are working as required. These terms encourage prompt and accurate delivery but rely on subjective assessment criteria such as the definition of 'working as specified' .

For Windows, the strategy involves creating a shortcut of the Python script's executable and placing it in the Startup folder, which ensures it runs automatically at system boot. This is done using the 'shell:startup' command in the Run dialog to open the Startup folder. For macOS and Linux, the strategy involves using either a cron job or a systemd service. A cron job is scheduled with a specific timing, whereas a systemd service is created to manage and start the executable at boot time, ensuring compatibility with the respective operating system's boot sequence management system .

You might also like