Django: Is it possible to insert /(slash) into InMemoryUploadedFile?

I have this bit of code.

        avatar = form.cleaned_data.get('avatar')

        name_extension = avatar.name # name of file + extension
        name, extension = name_extension.split(".") # split name and extension
        size = get_image_dimensions(avatar)  # image size
        file_name = "profileIMG" + '/' + user_name + '.' + extension # the actual string name 
                                                                     # that is going to be inserted in memory

        buffer = BytesIO()
        buffer.seek(0)

        path_and_img_name = InMemoryUploadedFile(buffer, 'ImageField', file_name, # load to memory
                                                 'image/' + extension, size, "utf-8")

I create a class InMemoryUploaded file, the only problem is, it doesn't save forward slashes and anything behind them. The Output should be:

        Data type is: <class 'django.core.files.uploadedfile.InMemoryUploadedFile'>  and data is:  profileIMG/RazzTazz25.jpg

But instead is:

        Data type is: <class 'django.core.files.uploadedfile.InMemoryUploadedFile'>  and data is:  RazzTazz25.jpg
        print("Data type is: ", type(path_and_img_name), " and data is: ", path_and_img_name)

I tried to escape the "/" with "\/", "\\/" but nothing works... I need this so I can save the class in the database, so It will direct me to the path I chose + change the name of the file.

        Profile.objects.filter(id=actual_image).update(avatar=path_and_img_name, title=title)

Any ideas?

Back to Top