2013-10-23 86 views
5

我使用Django 1.5在谷歌App Engine和我试图将文件上传到谷歌云存储。我正在使用gcs库,并且已经在settings.py中注册了一个自定义文件上传处理程序,作为我唯一的文件上传程序。我可以看到我的文件被正确上传的Blob存储在观众我的开发环境,但一旦form.save()被调用views.py我得到抛出说,这是一个只读的文件系统异常?我知道Google App Engine不允许访问文件系统,这就是为什么我首先使用GCS的原因!上传到谷歌云存储从Django的App Engine上

有什么我需要做的,从试图将文件保存到磁盘停止Django的?

相关的代码附加在这个gist

谢谢:)

堆栈跟踪:

Environment: 


Request Method: POST 
Request URL: http://localhost:8080/cms/media/add 

Django Version: 1.5 
Python Version: 2.7.5 
Installed Applications: 
('django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.staticfiles', 
'django.contrib.messages', 
'api', 
'cms', 
'frontend') 
Installed Middleware: 
('django.middleware.common.CommonMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware') 


Traceback: 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/handlers/base.py" in get_response 
    115.       response = callback(request, *callback_args, **callback_kwargs) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/contrib/auth/decorators.py" in _wrapped_view 
    25.     return view_func(request, *args, **kwargs) 
File "/Users/james/Dropbox/University/Year 4/Advanced Development/assignment/cms/views.py" in media_add_or_edit 
    44.    form.save() 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/forms/models.py" in save 
    370.        fail_message, commit, construct=False) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/forms/models.py" in save_instance 
    87.   instance.save() 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/base.py" in save 
    546.      force_update=force_update, update_fields=update_fields) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/base.py" in save_base 
    650.     result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/manager.py" in _insert 
    215.   return insert_query(self.model, objs, fields, **kwargs) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/query.py" in insert_query 
    1673.  return query.get_compiler(using=using).execute_sql(return_id) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/sql/compiler.py" in execute_sql 
    936.   for sql, params in self.as_sql(): 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/sql/compiler.py" in as_sql 
    894.     for obj in self.query.objs 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/fields/files.py" in pre_save 
    250.    file.save(file.name, file, save=False) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/fields/files.py" in save 
    86.   self.name = self.storage.save(name, content) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/files/storage.py" in save 
    48.   name = self._save(name, content) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/files/storage.py" in _save 
    198.      fd = os.open(full_path, flags, 0o666) 
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/stubs.py" in fake_open 
    71.  raise OSError(errno.EROFS, 'Read-only file system', filename) 

Exception Type: OSError at /cms/media/add 
Exception Value: [Errno 30] Read-only file system: u'/Users/james/Dropbox/University/Year 4/Advanced Development/assignment/IMG_0746.jpg' 
+0

可能还张贴你得到的堆栈跟踪? – jterrace

+0

@jterrace我刚刚添加了它。 –

+0

相关的,但也未回答:http://stackoverflow.com/questions/17338683/file-upload-in-django-modelform –

回答

2

我终于从我的模型移动FileField或进入我的ModelForm像这样解决了这个:

# Used for uploading media that forms part of a story 
class Media(models.Model): 
    title = models.CharField(max_length=100) 
    type = models.CharField(max_length=5, choices=MEDIA_TYPES) 
    content = models.TextField() 
    date_created = models.DateTimeField(auto_now_add=True) 

# Used to convert the media model to a form in the cms 
class MediaForm(forms.ModelForm): 
    file = forms.FileField() 

    class Meta: 
     model = Media 
     # Don't show the date created field because we want that to be set automatically 
     exclude = ('date_created', 'content',) 

我敢肯定,我之前尝试过,但似乎已经解决了我的问题,希望这可以帮助遇到同样问题的其他人。

相关问题