I tried everything, its not working, and i think i know why but i dont know how to fix it, im using this tutorial to upload in chunks to bypass the Cloudflare upload limitation of 100mb file
def create_post(request):
# s3_client=boto3.client('s3')
s3 = boto3.client('s3', region_name=settings.AWS_S3_REGION_NAME, aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY)
categories_1 = Category.objects.all()
if request.method == 'POST':
file = request.FILES['file'].read()
file_name_s3 = request.POST['filename']
fileName= request.POST['filename'].replace(' ', '')
fileName_STR = re.sub("[^A-Z]", "", fileName,0,re.IGNORECASE) + '.mp4'
existingPath = request.POST['existingPath']
end = request.POST['end']
image = request.FILES.get('image', False)
imageName = request.FILES.get('imagename', False)
if image != False:
image = request.FILES['image'].read()
imageName= request.POST['imagename'].replace(' ', '')
else:
pass
title = request.POST['title']
tags = request.POST['tags']
categories = parse_ids(request.POST['categories'])
description = request.POST['description']
nextSlice = request.POST['nextSlice']
if file=="" or fileName_STR=="" or existingPath=="" or end=="" or nextSlice=="":
res = JsonResponse({'data':'Invalid Request'})
return res
else:
if existingPath == 'null':
path = 'media/uploads/video_files/' + fileName
if image != False:
with open(path, 'wb+') as destination:
destination.write(file)
imagePath = 'media/thumbnail/' + imageName
else:
pass
if image:
with open(imagePath, 'wb+') as destination:
destination.write(image)
else:
pass
object_name = Path.joinpath(BASE_DIR, file_name_s3)
handles the upload...................
path = 'media/uploads/video_files/' + fileName_STR
with open(object_name, 'rb') as destination:
s3_client.upload_file(object_name ,bucket,fileName_STR)
............................................
FileFolder = Post()
FileFolder.video = 'uploads/video_files/'+fileName_STR
FileFolder.existingPath = fileName_STR
FileFolder.eof = end
FileFolder.title = title
FileFolder.author = request.user
FileFolder.description = description
if image == False:
FileFolder.thumbnail = None
else:
FileFolder.thumbnail = 'thumbnail/' + imageName
FileFolder.approved = True
FileFolder.save()
tag_list = taggit.utils._parse_tags(tags)
FileFolder.tags.add(*tag_list)
categories_post = Category.objects.filter(id__in=categories)
if categories_post:
for category in categories_post:
FileFolder.categories.add(category)
if int(end):
res = JsonResponse({'data':'Uploaded Successfully','existingPath': fileName})
else:
res = JsonResponse({'existingPath': fileName_STR})
return res
else:
path = 'media/uploads/video_files/' + existingPath
model_id = Post.objects.get(existingPath=existingPath)
if model_id.title == title:
if not model_id.eof:
with open(path, 'ab+') as destination:
destination.write(file)
if int(end):
model_id.eof = int(end)
model_id.save()
res = JsonResponse({'data':'Uploaded Successfully','existingPath':model_id.existingPath})
else:
res = JsonResponse({'existingPath':model_id.existingPath})
return res
else:
res = JsonResponse({'data':'EOF found. Invalid request'})
return res
else:
res = JsonResponse({'data':'No such file exists in the existingPath'})
return res
return render(request, 'main/create_post.html', {'categories': categories_1})
It gives me
with open(object_name, 'rb') as destination:
FileNotFoundError: [Errno 2] No such file or directory: '/home/mrlonely/Desktop/lumen/lumen/Bones - TheArtOfCremation-tqSpI1Jm0YE-1080p.mp4'
For now i just want to save the videos to S3, but the same procces is the same with images i think