0

I want to save a temporary uploaded file in the django os. How can I do that ?

The file is received as the following:

    file_obj = request.FILES['document']

I tried the following method but it saves the file in my AWS account but I just want to save it in the os and delete is as soon as I am done with it.

    file_name = default_storage.save(file_obj.name, file_obj)
    file_url = default_storage.url(file_name)

when I pass the file_url in a function and try to read it I get the following error:

OSError: [Errno 22] Invalid argument: 'https://xxxxxxxx.s3.amazonaws.com/media/Sample%20PFEP%20(2).xlsx'

I face no problem when I read the same file from local in my jupyter notebook. Why is that ?

Rahul Sharma
  • 2,187
  • 6
  • 31
  • 76
  • os? you mean *local storage* ? – JPG Nov 16 '20 at 08:24
  • @ArakkalAbu Yes, I figured that once I save it I can read it in function more easily – Rahul Sharma Nov 16 '20 at 08:24
  • Does this answer your question? [How to copy InMemoryUploadedFile object to disk](https://stackoverflow.com/questions/3702465/how-to-copy-inmemoryuploadedfile-object-to-disk) – JPG Nov 16 '20 at 08:25
  • @ArakkalAbu I tried ` tmp_file = os.path.join('pfep/', file_name)` but the file was not save at that location – Rahul Sharma Nov 16 '20 at 08:30
  • @ArakkalAbu Is there something as `os.save(request.Files['document']`?. I am unable to save the file from the above link – Rahul Sharma Nov 16 '20 at 08:49
  • Why do you want to save the file? Because you are going to delete it after some process, right? – JPG Nov 16 '20 at 09:27

0 Answers0