Django uploading file from disk to S3 using django-storages

In my Django project I use django-storages to save files to S3 uploaded via a Form. Model is defined as

class Uploads(models.Model):
    file = models.FileField(upload_to=GetUploadPath)

I'm making changes to the file that was uploaded via Form by saving to disk and then trying to pass a File object to the model.save() method.

with open(os.path.join(settings.MEDIA_ROOT, s),"rb") as f:
     file_to_s3 = File(f)

If I pass the file object using request.FILES.get('file') then the in-memory file gets uploaded properly, however when I try to upload the modified file from disk, I get this error,

RuntimeError: Input C:\Users\XXX\File.csv of type: <class 'django.core.files.base.File'> is not supported.

Followed this post but doesn't help, any thought's please.

Back to Top