Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
c0d33py committed Aug 23, 2023
1 parent 0aa8be2 commit 82d55f0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions django_tus/minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from django.conf import settings
from django.core.files.storage import default_storage
from tqdm import tqdm

from django_tus.connection import get_schema_name
from django_tus.models import TusFileModel


Expand All @@ -11,12 +13,14 @@ def __init__(self, tus_file):
self.client = default_storage.client
self.bucket_name = settings.MINIO_STORAGE_MEDIA_BUCKET_NAME
self.tus_file = tus_file
self.filename = self.tus_file.filename
self.resource_id = self.tus_file.resource_id

def upload_file(self, file_path):
with open(file_path, 'rb') as file:
self.client.put_object(
self.bucket_name,
self.tus_file.filename,
f'{get_schema_name()}/{self.filename}',
file,
length=-1,
part_size=10 * 1024 * 1024,
Expand All @@ -28,8 +32,8 @@ def upload_file(self, file_path):

def _save_uploaded_file_data(self):
# # Save the uploaded file data to a local file
file_obj = TusFileModel.objects.get(guid=self.tus_file.resource_id)
file_obj.uploaded_file = self.tus_file.filename
file_obj = TusFileModel.objects.get(guid=self.resource_id)
file_obj.uploaded_file = f'{get_schema_name()}/{self.filename}'
file_obj.save()

print(f"Uploaded file data saved: {self.tus_file.filename}")

0 comments on commit 82d55f0

Please sign in to comment.