You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing uploaded file using LocalStorageFileField #11
I have a Image model using the Document class, with a LocalStorageFileField for store in the filesystem(or S3), when i submit the form i can find the image file in the MEDIA_ROOT folder defined in settings.py
have same problem here .
but i solve this problem by saving image with define image
ex :
Post(Document):
image_post = LocalStorageFileField(required=False)
p = Post.objects.create(image_post=File) # if we add the file in here it's not store the file to Media
p.image_post.save('image_name',File) # this will create the image file on filesystem
i know it's not elegant but it's solved the store problem.
Would it be possible to have source code extract about your models, views, form & template ? because I tried since yesterday and I'm not able to get it to work.
I'm very novice in django & mongodb and it's a bit tricky for me ...
Currently, only filename is stored in DB. You will find my source code below. I'm not sure where I should use your workaround.
If you can help me it would be great :)
My model :
class Upload(Document):
name = StringField(max_length=255)
upload = LocalStorageFileField(required=True)
def __unicode__(self):
return u'%s' % (self.name)
My form :
class UploaderForm(forms.Form):
upload = forms.FileField()
def clean_upload(self):
upload = self.cleaned_data['upload']
content_type = upload.content_type
if content_type in settings.CONTENT_TYPES:
if upload.size > settings.MAX_UPLOAD_SIZE:
raise forms.ValidationError(('Please keep filesize under %s. Current filesize %s')
% (filesizeformat(settings.MAX_UPLOAD_SIZE), filesizeformat(upload.size)))
else:
raise forms.ValidationError(('File type is not supported'))
return upload
My view
def upload(request):
response_data = {}
if request.is_ajax():
form = UploaderForm(request.POST, request.FILES)
if form.is_valid():
upload = Upload.objects.create(
upload=request.FILES['upload']
)
upload.name = request.FILES['upload'].name
upload.save()
response_data['status'] = "success"
response_data['result'] = "Your file has been uploaded:"
response_data['fileLink'] = "/%s" % upload.upload
return HttpResponse(json.dumps(response_data), content_type="application/json")
response_data['status'] = "error"
response_data['result'] = "We're sorry, but something went wrong. Please be sure that your file respects the upload conditions."
if not request.GET:
return render_to_response('smartrip/addpicture.html', context_instance=RequestContext(request))
return HttpResponseRedirect('smartrip/success')
Activity
mishudark commentedon Feb 21, 2014
I have the same problem
weiztech commentedon Aug 18, 2014
have same problem here .
but i solve this problem by saving image with define image
ex :
Post(Document):
image_post = LocalStorageFileField(required=False)
p = Post.objects.create(image_post=File) # if we add the file in here it's not store the file to Media
p.image_post.save('image_name',File) # this will create the image file on filesystem
i know it's not elegant but it's solved the store problem.
edooby commentedon Feb 3, 2015
Would it be possible to have source code extract about your models, views, form & template ? because I tried since yesterday and I'm not able to get it to work.
I'm very novice in django & mongodb and it's a bit tricky for me ...
Currently, only filename is stored in DB. You will find my source code below. I'm not sure where I should use your workaround.
If you can help me it would be great :)
My model :
class Upload(Document):
name = StringField(max_length=255)
upload = LocalStorageFileField(required=True)
My form :
class UploaderForm(forms.Form):
upload = forms.FileField()
def clean_upload(self):
upload = self.cleaned_data['upload']
content_type = upload.content_type
if content_type in settings.CONTENT_TYPES:
if upload.size > settings.MAX_UPLOAD_SIZE:
raise forms.ValidationError(('Please keep filesize under %s. Current filesize %s')
% (filesizeformat(settings.MAX_UPLOAD_SIZE), filesizeformat(upload.size)))
else:
raise forms.ValidationError(('File type is not supported'))
return upload
My view
def upload(request):
response_data = {}
if request.is_ajax():
form = UploaderForm(request.POST, request.FILES)
My template :
{% csrf_token %}});