Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Django/DRF File Uploading to S3
const notifyDjango = (url) => {
// Record the URL of the file you've uploaded along with any data
// that is relevent to you.
const uploadToS3 = (file, url) => {
// Upload the file here
// See as a great example of handling all S3 upload edge cases.
const getSignedUrl = (file) => {
const params = {
contentType: file.type
client.get('/s3/signed-url/', { params })
.then(data => {
uploadToS3(file, data).then(i => {
// if success, record the new URL
.catch(error => {
from botocore.exceptions import ParamValidationError
from django.http import JsonResponse
def get_signed_url(request, *args, **kwargs):
object_name = request.GET.get('objectName')
content_type = request.GET.get('contentType')
url = conn.generate_presigned_url(
'Bucket': settings.S3_UPLOAD_BUCKET,
'Key': object_name,
'ContentType': content_type,
'ACL': 'public-read',
return JsonResponse({'signedUrl': url})
except ParamValidationError:
return JsonResponse({'error': 'Invalid Input'}, status=400)

This comment has been minimized.

Copy link

Akohrr commented Dec 28, 2018

Thank you very much. I'll definitely try this out next time I have to deal with file uploads in django.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.