filefield

Drupal 7: Rename files on upload (via filefield)

浪尽此生 提交于 2019-12-06 00:44:19
I am looking for a way to rename files that are uploaded by users through a filefield. For example, rename user profile photos using uniqid . I found a good solution for D6 at " Drupal 6: How to Change Filename on Upload " but can't find anything for D7. Another option is to use File (Field) Paths , but: The module causes warnings on my setup. Seems to be a bit of an overkill to install a general module for a very specific purpose. You can change every file upload by hook_file_presave as your desire pattern as example function yourmodulename_file_presave($file) { $parts = pathinfo($file-

Django REST Framework and FileField absolute url

本秂侑毒 提交于 2019-12-04 07:48:27
问题 I've defined a simple Django app that includes the following model: class Project(models.Model): name = models.CharField(max_length=200) thumbnail = models.FileField(upload_to='media', null=True) (Technically yes, that could have been an ImageField.) In a template, it's easy enough to include the MEDIA_URL value (duly coded in settings.py) as a prefix to the thumbnail URL. The following works fine: <div id="thumbnail"><img src="{{ MEDIA_URL }}{{ current_project.thumbnail }}" alt="thumbnail"

What is the clean way to unittest FileField in django?

女生的网名这么多〃 提交于 2019-12-03 01:35:51
问题 I have a model with a FileField. I want to unittest it. django test framework has great ways to manage database and emails. Is there something similar for FileFields? How can I make sure that the unittests are not going to pollute the real application? Thanks in advance PS: My question is almost a duplicate of Django test FileField using test fixtures but it doesn't have an accepted answer. Just want to re-ask if something new on this topic. 回答1: There are several ways you could tackle this

Django REST Framework and FileField absolute url

落爺英雄遲暮 提交于 2019-12-02 16:41:26
I've defined a simple Django app that includes the following model: class Project(models.Model): name = models.CharField(max_length=200) thumbnail = models.FileField(upload_to='media', null=True) (Technically yes, that could have been an ImageField.) In a template, it's easy enough to include the MEDIA_URL value (duly coded in settings.py) as a prefix to the thumbnail URL. The following works fine: <div id="thumbnail"><img src="{{ MEDIA_URL }}{{ current_project.thumbnail }}" alt="thumbnail" width="400" height="300" border="0" /></div> Using DRF, I've defined a HyperlinkedModelSerializer

Save base64 image in django file field

别说谁变了你拦得住时间么 提交于 2019-11-30 11:21:29
问题 I have following input "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA7YAAAISCAIAAAB3YsSDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAA5JxJREFUeNrsnQl4FEX6xqcJJEAS7ivhBkMAQTSJ4h0QEQ+I90rAc1cOL3QBXXV1AV1dVwmrsCqQ9VwJ6HoC7oon0T8iEkABwRC5IeE+kkAIkPT/nfmSmprunskk5CDw/p55hu7qOr76api8........" I want to save this file in file field. What can I do? models.py class SomeModel(models.Model): file = models.FileField(upload_to=get_upload_report) created = models.DateTimeField(auto_now_add=True)

How to show download link for attached file in FileField in Django Admin?

浪尽此生 提交于 2019-11-30 08:53:32
I have FileField in my django model: file = models.FileField(upload_to=FOLDER_FILES_PATH) In Django admin section for changing this model I have full path to this file (by default): Currently: /home/skyfox/Projects/fast_on_line/order_processor/orders_files/mydog2_2.jpg How can I show link for downloading this file for my admin panel users? If you have a model "Case" for example, you could add a method to your class which "creates" the link to the uploaded file : class Case(models.Model) ... file = models.FileField(upload_to=FOLDER_FILES_PATH) ... def file_link(self): if self.file: return "<a

Save base64 image in django file field

喜欢而已 提交于 2019-11-30 03:18:20
I have following input "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA7YAAAISCAIAAAB3YsSDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAA5JxJREFUeNrsnQl4FEX6xqcJJEAS7ivhBkMAQTSJ4h0QEQ+I90rAc1cOL3QBXXV1AV1dVwmrsCqQ9VwJ6HoC7oon0T8iEkABwRC5IeE+kkAIkPT/nfmSmprunskk5CDw/p55hu7qOr76api8........" I want to save this file in file field. What can I do? models.py class SomeModel(models.Model): file = models.FileField(upload_to=get_upload_report) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) I'm trying to do this def get_file(data): from django.core

How to upload a file in rails?

北城以北 提交于 2019-11-29 22:56:59
问题 I'm new to rails. I want to know about file uploading process in rails. Can anyone please help me... Thanks, Althaf 回答1: Usually gems/plugins are used to to handle file uploads. My favorite one, and perhaps the most ubiquitous is Paperclip. In your view, you'll have to tell the rails form helpers that you're uploading a file like this: <%= form_for @model, :html => { :multipart => true } do |form| %> 回答2: Here is a method on how to upload file without using any gem and only by using rails,

How to show download link for attached file in FileField in Django Admin?

北慕城南 提交于 2019-11-29 12:36:03
问题 I have FileField in my django model: file = models.FileField(upload_to=FOLDER_FILES_PATH) In Django admin section for changing this model I have full path to this file (by default): Currently: /home/skyfox/Projects/fast_on_line/order_processor/orders_files/mydog2_2.jpg How can I show link for downloading this file for my admin panel users? 回答1: If you have a model "Case" for example, you could add a method to your class which "creates" the link to the uploaded file : class Case(models.Model)

Django test FileField using test fixtures

痴心易碎 提交于 2019-11-28 22:27:41
问题 I'm trying to build tests for some models that have a FileField. The model looks like this: class SolutionFile(models.Model): ''' A file from a solution. ''' solution = models.ForeignKey(Solution) file = models.FileField(upload_to=make_solution_file_path) I have encountered two problems: When saving data to a fixture using ./manage.py dumpdata , the file contents are not saved, only the file name is saved into the fixture. While I find this to be the expected behavior as the file contents are