The error message suggests that you are passing an object of type InMemoryUploadedFile to the _getfullpathname function, which expects a string, bytes, or an instance of os.PathLike.

To resolve this error, you need to convert the InMemoryUploadedFile object to a string or bytes object that can be passed to _getfullpathname. You can do this by calling the read() method of the file object to retrieve the contents of the uploaded file as bytes, and then decoding it to a string using the appropriate encoding, such as UTF-8.

Here is an example of how you can convert an InMemoryUploadedFile object to a string:

import os

def get_full_pathname(file_obj):
    # Get the file contents as bytes
    file_contents = file_obj.read()
    # Decode the bytes to a string using UTF-8 encoding
    file_str = file_contents.decode('utf-8')
    # Get the full path of the file
    full_pathname = os.path.abspath(file_str)
    return full_pathname

In this example, we define a function get_full_pathname that takes an InMemoryUploadedFile object and returns the full pathname of the uploaded file. The function reads the contents of the file using the read() method, decodes the bytes to a string using UTF-8 encoding, and then calls os.path.abspath to get the full path of the file

_getfullpathname path should be string bytes or osPathLike not InMemoryUploadedFile

原文地址: https://www.cveoy.top/t/topic/hwDk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录