I'm testing out a few options. I have uploaded a file using django-storages with S3 and it works fine. However, when I try and read the file with the code below I get the following error:
'FieldFile' object has no attribute 'startswith'
Why?
Even default_storage.exists(self.filepath) give the same error.
csv_file = default_storage.open(self.filepath, 'r')
new_object = CSVImport(csvfile=csv_file.read(),
model=Contact,
modelspy=".",
mappings="1=first_name,2=mobile,3=email,4=last_name,5=43,6=16")
new_object.run()
Full Error:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/contacts/upload/configurator/95/
Django Version: 1.5.1
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.humanize',
'django.contrib.sitemaps',
'south',
'userena',
'social_auth',
'djcelery',
'storages',
'endless_pagination',
'django.contrib.flatpages',
'django_sagepay',
'guardian',
'widget_tweaks',
'badger',
'tastypie',
'accounts',
'contacts',
'sms',
'smartpages',
'django_sagepay',
'unsubscribe',
'core',
'django_nose',
'debug_toolbar')
Installed Middleware:
('dogslow.WatchdogMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'async_messages.middleware.AsyncMiddleware',
'core.middleware.ssl.SSLRedirect',
'core.middleware.account.RefreshBalance',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/Users/user/Documents/workspace/t/django-env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/user/Documents/workspace/t/django-env/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
25. return view_func(request, *args, **kwargs)
File "/Users/user/Documents/workspace/t/contacts/views.py" in upload_configurator
201. process_upload_Temp(upload_id=upload.id, cleaned_data=data)
File "/Users/user/Documents/workspace/t/contacts/views.py" in process_upload_Temp
222. upload.process(cleaned_data=cleaned_data)
File "/Users/user/Documents/workspace/t/contacts/models.py" in process
169. csv_file = default_storage.open(self.filepath, 'r')
File "/Users/user/Documents/workspace/t/django-env/lib/python2.7/site-packages/django/core/files/storage.py" in open
36. return self._open(name, mode)
File "/Users/user/Documents/workspace/t/django-env/lib/python2.7/site-packages/storages/backends/s3boto.py" in _open
237. name = self._normalize_name(self._clean_name(name))
File "/Users/user/Documents/workspace/t/django-env/lib/python2.7/site-packages/storages/backends/s3boto.py" in _clean_name
204. return os.path.normpath(name).replace('\\', '/')
File "/Users/user/Documents/workspace/t/django-env/lib/python2.7/posixpath.py" in normpath
318. initial_slashes = path.startswith('/')
Exception Type: AttributeError at /contacts/upload/configurator/95/
Exception Value: 'FieldFile' object has no attribute 'startswith'
I have tried:
csv_file.read() gives same error.
Full Error details: