Hello to All! I need your help figuring out how to solve this issue I'm having while trying to upload directly to s3 bucket. I have a function that works perfectly outside of django, I'm trying to implement it within django so as to be able to upload directly to s3.
1. I do want to first save the file locally 2. Though I'm testing it with one s3 bucket, ultimately the application will deal with several buckets; I'm not trying to use s3 as a storage/backend, but rather to use django's UI as a file transfer point from any end user to his s3 bucket. This is my scripts ( #function carrying out the upload to s3 def s3_upload_file(file_name, bucket, object_name=None): if object_name is None: object_name = file_name # Upload the file s3_client = boto3.client('s3') try: response = s3_client.upload_file(file_name, bucket, object_name) except ClientError as e: logging.error(e) return False return True #function serving to upload the file - linked to UI/django form #@login_required def upload_file(request): if request.method == 'POST': form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): file = request.FILES['file'].name file = str(file) s3_upload_file(file, 'django-to-s3')#calling the fucntion # as it takes the uploaded file as input. return HttpResponseRedirect('/success/url/') else: form = UploadFileForm() return render(request, 'aws/file_upload.html', {'form': form}) I'm using this line: file = str(file), in attempt to cast request.FILES['file'] as a string, otherwise s3_upload_file(file, 'django-to-s3') throws an error. Attached are screenshots of what I get when I run the cmd python manage.py runserver I will truly appreciate your help. Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a1848b26-3b08-4178-9ec8-2f96a3506d28n%40googlegroups.com.