[Answered ]-FieldFile object has no attribute 'startswith'

2👍

the error is thrown by:

csv_file = default_storage.open(self.filepath, 'r')

which tells that the type of self.filepath is FieldFile. So given its name, I’d expect that object to be an already opened file. So you should try:

new_object = CSVImport(csvfile=self.filepath.read(), ... )

But I may be wrong, and self.filepath could be a file containing the path to the file you want to open… It’s hard to tell given your code sample, I can only guess.

👤zmo

0👍

Your are passing a FieldFile object to default_storage.open() but it expects the file name as a string. Give it the name that was used to save the file instead of a FieldFile object.

Leave a comment