File Upload in Django modelForm

2019-06-26 17:16发布

I am trying to upload documets in appengine-django. Docs getting uploaded successfully with pure django code [ using python manage.py runsever ]. But when i am trying to run django with appengine project it gives me error ,

[Errno 30] Read-only file system: u'/home/nishant/workspace1/problemdemo/uploaded_files/1372313114_43_nishant26062013.zip'

This error caused because Developers have read-only access to the filesystem on App Engine.

Is there is another way to upload docs to google cloud sql ?

Here is my code ,

models.py

from django.db import models
import time

# Create your models here.

def get_upload_file_name(instance,filename):
    return "uploaded_files/%s_%s" % (str(time.time()).replace('.','_'),filename)


class Candidate(models.Model):
    title=models.CharField(max_length=20)
    resume=models.FileField(upload_to=get_upload_file_name)

    def __unicode__(self):
        return self.title

forms.py

from django import forms
from actualproblem.models import Candidate

class TestForm(forms.ModelForm):

    class Meta:

        model=Candidate

        fields=('title','resume',)

views.py

# Create your views here.
from django.shortcuts import render
from actualproblem.forms import TestForm

def sampletest(request):


    if request.method=='POST':        
        form = TestForm(request.POST,request.FILES)
        if form.is_valid():
            form.save()

    else:
        form=TestForm()


    return render(request,'profile.html',{'form':form})

How can i upload documetns to google cloud sql ?

1条回答
叛逆
2楼-- · 2019-06-26 17:45

You may solve the conundrum by using Uploadcare, it can help in situations when you have little or no control over host filesystem (GAE, heroku, shared hosting or whatnot). Uploaded files will be stored in Uploadcare and you will store file UUIDs or URLs in your DB.

There is Django package: pyuploadcare

disclosure: I am one of Uploadcare developers and am posting this not to shamelessly promote the service but because it was built to solve cases like this one.

查看更多
登录 后发表回答