| Name | MT-PY-File-upload JSON |
| Version |
0.2.2
JSON |
| download |
| home_page | |
| Summary | A package to implementing file upload in AWS s3 bucket and store mysqlite,msql,postgress |
| upload_time | 2023-09-22 12:37:08 |
| maintainer | |
| docs_url | None |
| author | Viraj Poojari |
| requires_python | >=3.7 |
| license | |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# MT-PY-File-upload
# Upload File to AWS S3
This script demonstrates how to upload a file to AWS S3 using the
` boto3 `
library in Python.
## Prerequisites
- Python 3.x
- AWS account with S3 access
- AWS credentials configured (via environment variables or AWS CLI)
## Setup
1. Install the required dependencies by running the following command:
```cmd
pip install MT-PY-File-upload
```
2. Some support-package to work with file upload package.
```cmd
pip instal boto3 python-dotenv
```
* Create a .env file in the same directory as the script and provide the necessary
AWS credentials and region:
```note
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
AWS_S3_REGION_NAME=your-s3-region
AWS_STORAGE_BUCKET_NAME=bucket-name
```
## Usage
### Import the necessary libraries:
```py
import boto3
import os
from mt_django_file_upload.upload_file_to_s3 import Upload_file_to_s3
from dotenv import load_dotenv
load_dotenv()
```
* Define the function Upload_file_to_s3 to upload a file to S3:
```py
Upload_file_to_s3(file_path, bucket_name, object_name,aws_access_key,
aws_secret_key,region_name )
```
* Call the function with the required parameters:
```py
Upload_file_to_s3("path/to/file", "your-bucket-name", "object-key-name",
"aws_access_key","aws_secret_key","region_name")
```
## References
[boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html)
[python-dotenv documentation](https://github.com/theskumar/python-dotenv)
# Azure Blob Storage Upload Package
This package provides functions to upload files to Azure Blob Storage.
### Installation
You can install this package using pip:
## Prerequisites
- Python 3.x
- Azure account
- storage accounts
- create container with blog storage facility.
## Setup
1. Install the required dependencies by running the following command:
```cmd
pip install MT-PY-File-upload
```
2. Some support-package to work with file upload package.
```cmd
pip instal azure-core azure-storage-blob python-dotenv
```
* Create a .env file in the same directory as the script and provide the necessary
AWS credentials and region:
```note
AZURE_STORAGE_ACCOUNT_KEY='azure-account-key'
AZURE_STORAGE_ACCOUNT_NAME="storage-name"
AZURE_CONTAINER_NAME="contaier-name"
AZURE_CONNECTION_STRING="Connection string"
```
## Usage
### Import the necessary libraries:
```py
import os
from mt_django_file_upload.azureBlobStorage import uploadToBlobStorage
from dotenv import load_dotenv
load_dotenv()
```
* Define the function uploadToBlobStorage to upload a file to S3:
* Call the function with the required parameters:
```py
uploadToBlobStorage("path/to/file", "your-bucket-name", "object-key-name",
"aws_access_key","aws_secret_key","region_name")
```
### Parameters:
* file_path (str): Path to the file you want to upload.
* file_name (str): Name to give to the file in the storage.
* storage_account_key (str): Your Azure Storage Account key.
* storage_account_name (str): Your Azure Storage Account name.
* container_name (str): Name of the container in Azure Blob Storage.
* connection_string (str): Azure Storage Account connection string.
### Example
```py
from mt_django_file_upload import azureBlobStorage
file_path = "path/to/your/file.txt"
file_name = "example_file.txt"
storage_account_key = "YOUR_STORAGE_ACCOUNT_KEY"
storage_account_name = "YOUR_STORAGE_ACCOUNT_NAME"
container_name = "YOUR_CONTAINER_NAME"
connection_string = "YOUR_CONNECTION_STRING"
uploadToBlobStorage(file_path, file_name, storage_account_key,
storage_account_name, container_name, connection_string)
```
## References
[azure core documentation](https://learn.microsoft.com/en-us/dotnet/api/overview/azure/core-readme?view=azure-dotnet)
[python-dotenv documentation](https://github.com/theskumar/python-dotenv)
# Custom FileField with Extension Validation
This code provides custom file field classes for Django models with extension validation.
It extends Django's built-in FileField and adds additional validation for allowed file extensions.
## Prerequisites
- Django framework
## Usage
### Mt_FileField
A custom FileField that validates the file extension based on a list of allowed extensions.
### Example usage:
```py
from django.db.models import FileField
from django.core.validators import FileExtensionValidator
class Mt_FileField(FileField):
def __init__(self, *args, allowed_extensions=None, **kwargs):
self.allowed_extensions = allowed_extensions or []
super().__init__(*args, **kwargs)
def validate(self, value, model_instance):
super().validate(value, model_instance)
# Use Django's FileExtensionValidator to validate the file extension
validator = FileExtensionValidator(allowed_extensions=self.allowed_extensions)
# Validate the file
try:
validator(value)
except ValidationError as e:
# If the file is not valid, raise a ValidationError with a custom error message
raise ValidationError('Invalid file format. Only {} files are allowed.'.format(
', '.join(self.allowed_extensions))
) from e
```
# Custom FileField with Extension Validation
This code provides custom file field classes for Django models
with extension validation. It extends Django's built-in FileField
and adds additional validation for allowed file extensions.
## Usage
## Mt_FileField
A custom FileField that validates the file extension based on a list of allowed extensions.
## implement in models.py
### Example:
```py
from mt_django_file_upload.file_upload import Mt_fileUploadField,Mt_FileField
class SaveFile(models.Model):
file1=Mt_fileUploadField(upload_to="newDoc",null=True,blank=True)
# Yo can limit your file fields
file2=Mt_FileField(upload_to="doc",
null=True,blank=True,allowed_extensions=['txt','doc','docx'])
```
## implement in views.py
### Example:
```py
def home(request,*args,**kwargs):
if(request.method=="POST"):
filled_form=Doc_fields(request.POST,request.FILES)
note=''
header = "Upload folder form"
if(filled_form.is_valid()):
filled_form.save()
note=f"{filled_form.cleaned_data['text']} item was saved successfully"
else:
note="Somthing went wrong"
return render(request,'local_upload/index.html',
{"note":note,"form":
filled_form,"header":"Save file,image using mt_django_file_upload package in mysqlite"})
else:
form =Doc_fields()
return render(request,"local_upload/index.html",{"form":form,
"header":"Saving file,image using mt_django_file_upload package in mysqlite"})
def example(request):
context={
"hello":_("Hello")
}
return render(request,'local_upload/example.html',context)
```
## implement in settings.py
### Example:
```py
MEDIA_ROOT=BASE_DIR/'media'
MEDIA_URL='/media/'
```
* **You can change database by changing database configuration in settings.py**
```py
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
```
```py
from django.db.models import FileField
from django.core.validators import FileExtensionValidator
class Mt_FileField(FileField):
def __init__(self, *args, allowed_extensions=None, **kwargs):
self.allowed_extensions = allowed_extensions or []
super().__init__(*args, **kwargs)
def validate(self, value, model_instance):
super().validate(value, model_instance)
# Use Django's FileExtensionValidator to validate the file extension
validator = FileExtensionValidator(allowed_extensions=self.allowed_extensions)
# Validate the file
try:
validator(value)
except ValidationError as e:
# If the file is not valid, raise a ValidationError with a custom error message
raise ValidationError('Invalid file format. Only {} files are allowed.'.format(
', '.join(self.allowed_extensions))
) from e
```
## Mt_form_fileUploadField
A custom form file field that extends Django's built-in FileField.
### Example usage:
```py
from django.forms import FileField as f_FileField
class Mt_form_fileUploadField(f_FileField):
pass
```
## Mt_fileUploadField
A custom file field that extends Django's built-in FileField.
### Example usage:
```py
from django.db.models import FileField
class Mt_fileUploadField(FileField):
pass
```
## References
[Django FileField documentation](https://docs.djangoproject.com/en/4.2/ref/models/fields/#filefield)
[Django FileExtensionValidator documentation](https://docs.djangoproject.com/en/4.2/ref/validators/#fileextensionvalidator)
```note
This documentation provides an overview of the custom field classes and how to use them in
your Django models or forms. It also includes references to the relevant Django documentation
for further details.
```
Raw data
{
"_id": null,
"home_page": "",
"name": "MT-PY-File-upload",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Viraj Poojari",
"author_email": "Viraj <virajpoojari0905@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/f4/ea/a317fb6c2b4243768906321bac0c1b2496a8e7677a9cfea53db962e73e0e/MT_PY_File_upload-0.2.2.tar.gz",
"platform": null,
"description": "# MT-PY-File-upload\r\n# Upload File to AWS S3\r\n\r\nThis script demonstrates how to upload a file to AWS S3 using the \r\n` boto3 ` \r\nlibrary in Python.\r\n\r\n## Prerequisites\r\n\r\n- Python 3.x\r\n- AWS account with S3 access\r\n- AWS credentials configured (via environment variables or AWS CLI)\r\n\r\n## Setup\r\n\r\n1. Install the required dependencies by running the following command:\r\n\r\n```cmd\r\n pip install MT-PY-File-upload \r\n```\r\n2. Some support-package to work with file upload package.\r\n\r\n```cmd\r\npip instal boto3 python-dotenv\r\n```\r\n\r\n* Create a .env file in the same directory as the script and provide the necessary \r\nAWS credentials and region:\r\n\r\n```note\r\nAWS_ACCESS_KEY_ID=your-access-key-id\r\nAWS_SECRET_ACCESS_KEY=your-secret-access-key\r\nAWS_S3_REGION_NAME=your-s3-region\r\nAWS_STORAGE_BUCKET_NAME=bucket-name\r\n```\r\n\r\n## Usage\r\n### Import the necessary libraries:\r\n\r\n```py\r\nimport boto3\r\nimport os\r\n\r\nfrom mt_django_file_upload.upload_file_to_s3 import Upload_file_to_s3\r\nfrom dotenv import load_dotenv\r\nload_dotenv()\r\n\r\n```\r\n\r\n* Define the function Upload_file_to_s3 to upload a file to S3:\r\n\r\n```py\r\nUpload_file_to_s3(file_path, bucket_name, object_name,aws_access_key,\r\n aws_secret_key,region_name )\r\n\r\n```\r\n\r\n* Call the function with the required parameters:\r\n\r\n```py\r\nUpload_file_to_s3(\"path/to/file\", \"your-bucket-name\", \"object-key-name\",\r\n\"aws_access_key\",\"aws_secret_key\",\"region_name\")\r\n\r\n```\r\n## References\r\n\r\n[boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html)\r\n[python-dotenv documentation](https://github.com/theskumar/python-dotenv)\r\n\r\n# Azure Blob Storage Upload Package\r\nThis package provides functions to upload files to Azure Blob Storage.\r\n\r\n### Installation\r\nYou can install this package using pip:\r\n## Prerequisites\r\n\r\n- Python 3.x\r\n- Azure account \r\n- storage accounts \r\n- create container with blog storage facility.\r\n\r\n## Setup\r\n\r\n1. Install the required dependencies by running the following command:\r\n\r\n```cmd\r\n pip install MT-PY-File-upload \r\n```\r\n2. Some support-package to work with file upload package.\r\n\r\n```cmd\r\npip instal azure-core azure-storage-blob python-dotenv\r\n```\r\n\r\n* Create a .env file in the same directory as the script and provide the necessary \r\nAWS credentials and region:\r\n\r\n```note\r\nAZURE_STORAGE_ACCOUNT_KEY='azure-account-key'\r\nAZURE_STORAGE_ACCOUNT_NAME=\"storage-name\"\r\nAZURE_CONTAINER_NAME=\"contaier-name\"\r\nAZURE_CONNECTION_STRING=\"Connection string\"\r\n```\r\n## Usage\r\n### Import the necessary libraries:\r\n\r\n```py\r\nimport os \r\nfrom mt_django_file_upload.azureBlobStorage import uploadToBlobStorage\r\nfrom dotenv import load_dotenv\r\nload_dotenv()\r\n```\r\n\r\n* Define the function uploadToBlobStorage to upload a file to S3:\r\n\r\n\r\n* Call the function with the required parameters:\r\n\r\n```py\r\nuploadToBlobStorage(\"path/to/file\", \"your-bucket-name\", \"object-key-name\",\r\n\"aws_access_key\",\"aws_secret_key\",\"region_name\")\r\n\r\n```\r\n\r\n### Parameters:\r\n\r\n* file_path (str): Path to the file you want to upload.\r\n* file_name (str): Name to give to the file in the storage.\r\n* storage_account_key (str): Your Azure Storage Account key.\r\n* storage_account_name (str): Your Azure Storage Account name.\r\n* container_name (str): Name of the container in Azure Blob Storage.\r\n* connection_string (str): Azure Storage Account connection string.\r\n\r\n### Example\r\n```py\r\n\r\nfrom mt_django_file_upload import azureBlobStorage\r\n\r\nfile_path = \"path/to/your/file.txt\"\r\nfile_name = \"example_file.txt\"\r\nstorage_account_key = \"YOUR_STORAGE_ACCOUNT_KEY\"\r\nstorage_account_name = \"YOUR_STORAGE_ACCOUNT_NAME\"\r\ncontainer_name = \"YOUR_CONTAINER_NAME\"\r\nconnection_string = \"YOUR_CONNECTION_STRING\"\r\n\r\nuploadToBlobStorage(file_path, file_name, storage_account_key, \r\n storage_account_name, container_name, connection_string)\r\n```\r\n\r\n\r\n## References\r\n[azure core documentation](https://learn.microsoft.com/en-us/dotnet/api/overview/azure/core-readme?view=azure-dotnet)\r\n[python-dotenv documentation](https://github.com/theskumar/python-dotenv)\r\n\r\n# Custom FileField with Extension Validation\r\n\r\nThis code provides custom file field classes for Django models with extension validation. \r\nIt extends Django's built-in FileField and adds additional validation for allowed file extensions.\r\n\r\n## Prerequisites\r\n\r\n- Django framework\r\n\r\n## Usage\r\n\r\n### Mt_FileField\r\n\r\nA custom FileField that validates the file extension based on a list of allowed extensions.\r\n\r\n### Example usage:\r\n\r\n```py\r\nfrom django.db.models import FileField\r\nfrom django.core.validators import FileExtensionValidator\r\n\r\nclass Mt_FileField(FileField):\r\n def __init__(self, *args, allowed_extensions=None, **kwargs):\r\n self.allowed_extensions = allowed_extensions or []\r\n super().__init__(*args, **kwargs)\r\n\r\n def validate(self, value, model_instance):\r\n super().validate(value, model_instance)\r\n\r\n # Use Django's FileExtensionValidator to validate the file extension\r\n validator = FileExtensionValidator(allowed_extensions=self.allowed_extensions)\r\n\r\n # Validate the file\r\n try:\r\n validator(value)\r\n except ValidationError as e:\r\n # If the file is not valid, raise a ValidationError with a custom error message\r\n raise ValidationError('Invalid file format. Only {} files are allowed.'.format(\r\n ', '.join(self.allowed_extensions))\r\n ) from e\r\n```\r\n\r\n# Custom FileField with Extension Validation\r\n\r\nThis code provides custom file field classes for Django models \r\nwith extension validation. It extends Django's built-in FileField\r\nand adds additional validation for allowed file extensions.\r\n\r\n\r\n## Usage\r\n\r\n## Mt_FileField\r\n\r\nA custom FileField that validates the file extension based on a list of allowed extensions.\r\n\r\n\r\n\r\n## implement in models.py\r\n### Example:\r\n\r\n\r\n```py\r\nfrom mt_django_file_upload.file_upload import Mt_fileUploadField,Mt_FileField\r\nclass SaveFile(models.Model):\r\n file1=Mt_fileUploadField(upload_to=\"newDoc\",null=True,blank=True)\r\n # Yo can limit your file fields\r\n file2=Mt_FileField(upload_to=\"doc\", \r\n null=True,blank=True,allowed_extensions=['txt','doc','docx'])\r\n```\r\n## implement in views.py\r\n### Example:\r\n\r\n```py\r\ndef home(request,*args,**kwargs):\r\n if(request.method==\"POST\"):\r\n\r\n filled_form=Doc_fields(request.POST,request.FILES)\r\n note=''\r\n header = \"Upload folder form\"\r\n\r\n if(filled_form.is_valid()):\r\n filled_form.save()\r\n note=f\"{filled_form.cleaned_data['text']} item was saved successfully\"\r\n else:\r\n note=\"Somthing went wrong\"\r\n return render(request,'local_upload/index.html',\r\n {\"note\":note,\"form\":\r\n filled_form,\"header\":\"Save file,image using mt_django_file_upload package in mysqlite\"}) \r\n else:\r\n form =Doc_fields()\r\n return render(request,\"local_upload/index.html\",{\"form\":form,\r\n \"header\":\"Saving file,image using mt_django_file_upload package in mysqlite\"})\r\n \r\ndef example(request):\r\n context={\r\n \"hello\":_(\"Hello\")\r\n }\r\n return render(request,'local_upload/example.html',context)\r\n```\r\n## implement in settings.py\r\n### Example:\r\n\r\n```py\r\nMEDIA_ROOT=BASE_DIR/'media'\r\nMEDIA_URL='/media/'\r\n```\r\n* **You can change database by changing database configuration in settings.py**\r\n```py\r\n# Database\r\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\r\n\r\nDATABASES = {\r\n 'default': {\r\n 'ENGINE': 'django.db.backends.sqlite3',\r\n 'NAME': BASE_DIR / 'db.sqlite3',\r\n }\r\n}\r\n```\r\n```py\r\nfrom django.db.models import FileField\r\nfrom django.core.validators import FileExtensionValidator\r\n\r\nclass Mt_FileField(FileField):\r\n def __init__(self, *args, allowed_extensions=None, **kwargs):\r\n self.allowed_extensions = allowed_extensions or []\r\n super().__init__(*args, **kwargs)\r\n\r\n def validate(self, value, model_instance):\r\n super().validate(value, model_instance)\r\n\r\n # Use Django's FileExtensionValidator to validate the file extension\r\n validator = FileExtensionValidator(allowed_extensions=self.allowed_extensions)\r\n\r\n # Validate the file\r\n try:\r\n validator(value)\r\n except ValidationError as e:\r\n # If the file is not valid, raise a ValidationError with a custom error message\r\n raise ValidationError('Invalid file format. Only {} files are allowed.'.format(\r\n ', '.join(self.allowed_extensions))\r\n ) from e\r\n```\r\n\r\n## Mt_form_fileUploadField\r\nA custom form file field that extends Django's built-in FileField.\r\n\r\n### Example usage:\r\n\r\n```py\r\n\r\nfrom django.forms import FileField as f_FileField\r\n\r\nclass Mt_form_fileUploadField(f_FileField):\r\n pass\r\n```\r\n## Mt_fileUploadField\r\nA custom file field that extends Django's built-in FileField.\r\n\r\n### Example usage:\r\n\r\n```py\r\n\r\nfrom django.db.models import FileField\r\n\r\nclass Mt_fileUploadField(FileField):\r\n pass\r\n```\r\n\r\n\r\n## References\r\n[Django FileField documentation](https://docs.djangoproject.com/en/4.2/ref/models/fields/#filefield)\r\n[Django FileExtensionValidator documentation](https://docs.djangoproject.com/en/4.2/ref/validators/#fileextensionvalidator)\r\n\r\n```note\r\n\r\nThis documentation provides an overview of the custom field classes and how to use them in \r\nyour Django models or forms. It also includes references to the relevant Django documentation\r\nfor further details.\r\n\r\n```\r\n",
"bugtrack_url": null,
"license": "",
"summary": "A package to implementing file upload in AWS s3 bucket and store mysqlite,msql,postgress",
"version": "0.2.2",
"project_urls": {
"Bug Tracker": "https://github.com/pypa/sampleproject/issues",
"Homepage": "https://github.com/pypa/sampleproject"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4b107c4d3ffd17356ba0e4b7505545ab5f01d71692114b123dbb08a841b0cba3",
"md5": "ccb80cdc845039a9f1b412f1eea2e18a",
"sha256": "645a418aa86f713bc28215d6f2469b01eab5a4cfb638d5f7ce2d273b1699407c"
},
"downloads": -1,
"filename": "MT_PY_File_upload-0.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ccb80cdc845039a9f1b412f1eea2e18a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 8055,
"upload_time": "2023-09-22T12:37:05",
"upload_time_iso_8601": "2023-09-22T12:37:05.009053Z",
"url": "https://files.pythonhosted.org/packages/4b/10/7c4d3ffd17356ba0e4b7505545ab5f01d71692114b123dbb08a841b0cba3/MT_PY_File_upload-0.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f4eaa317fb6c2b4243768906321bac0c1b2496a8e7677a9cfea53db962e73e0e",
"md5": "1c57a6af64162bb381ad8b1451768746",
"sha256": "1f2d10a5cda6effa07eb60b2850f34086278efc8706d51d6a689831d139d59dd"
},
"downloads": -1,
"filename": "MT_PY_File_upload-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "1c57a6af64162bb381ad8b1451768746",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 6649,
"upload_time": "2023-09-22T12:37:08",
"upload_time_iso_8601": "2023-09-22T12:37:08.317401Z",
"url": "https://files.pythonhosted.org/packages/f4/ea/a317fb6c2b4243768906321bac0c1b2496a8e7677a9cfea53db962e73e0e/MT_PY_File_upload-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-22 12:37:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pypa",
"github_project": "sampleproject",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "mt-py-file-upload"
}