filefield

How to localize the label of a file_field in Rails?

好久不见. 提交于 2020-01-17 08:17:09
问题 I want to localize a form in my app so that all the labels are in Finnish. This is easy with all other form components, but how do I do this with a file field? It always seems to give me a label "choose file" in the button and "no file chosen" immediately after the button. 回答1: This dumb file field depends only on your system locale. You cannot change way it looks or behaves, which annoys many of us, not to mention the fact that it can look completely different across different platforms. To

Drupal 7: Rename files on upload (via filefield)

半腔热情 提交于 2020-01-13 14:54:10
问题 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. 回答1: You can change every file upload by hook_file_presave as

Avoid copying when adding a large file to FileField

天涯浪子 提交于 2020-01-05 04:41:12
问题 I'm dealing with some quite large files which are uncomfortable to upload via http, so my users upload files using FTP which my code then needs to move into FileField.upload_to (where they normally end up when uploaded via HTTP). My problem is, the commonly suggested method of using django.core.files.File : from django.core.files import File # filename is a FileField file_obj = MyModel(filename=File(open('VIDEO_TS.tar', 'rb'))) leads to copying the data, which i need to avoid. Is there any

Avoid copying when adding a large file to FileField

陌路散爱 提交于 2020-01-05 04:41:12
问题 I'm dealing with some quite large files which are uncomfortable to upload via http, so my users upload files using FTP which my code then needs to move into FileField.upload_to (where they normally end up when uploaded via HTTP). My problem is, the commonly suggested method of using django.core.files.File : from django.core.files import File # filename is a FileField file_obj = MyModel(filename=File(open('VIDEO_TS.tar', 'rb'))) leads to copying the data, which i need to avoid. Is there any

Django model with FileField — dynamic 'upload_to' argument

佐手、 提交于 2019-12-31 10:43:38
问题 I am using the model with FileField to deal with file uploading. Now the files can be uploaded successfully. However, there is one more small improvement I want to make, which is to create folder for the user with the username. Here is the code I've tried class UserFiles(models.Model): user = models.OneToOneField(User) file = models.FileField(upload_to='files/users/user.username/%Y_%m_%d/') this would give the folder of 'user.username' instead of 'John'(one example of username) I have also

Django model with FileField — dynamic 'upload_to' argument

▼魔方 西西 提交于 2019-12-31 10:42:18
问题 I am using the model with FileField to deal with file uploading. Now the files can be uploaded successfully. However, there is one more small improvement I want to make, which is to create folder for the user with the username. Here is the code I've tried class UserFiles(models.Model): user = models.OneToOneField(User) file = models.FileField(upload_to='files/users/user.username/%Y_%m_%d/') this would give the folder of 'user.username' instead of 'John'(one example of username) I have also

how to find height and width of image for FileField Django

半世苍凉 提交于 2019-12-25 04:48:07
问题 How to find height and width of image if our model is defined as follow class MModel: document = FileField() format_type = CharField() and image is saved in document then how we can find height and width of a document if it is image ? 回答1: If the files will always be images, change FileField to ImageField, like this: def MyModel(models.Model): height = models.IntegerField() width = models.IntegerField() document = models.ImageField(height_field='height', width_field='width') Otherwise, you'll

Accept Image in Filefield ExtJs

久未见 提交于 2019-12-24 01:50:19
问题 I have a filefield componente in my application and I want to restrict it to only image files. I've found this question on stackoverflow: How to restrict file type using xtype filefield(extjs 4.1.0)? Add accept="image/*" attribute to input field in ExtJs I'm using this code: { xtype:'filefield', listeners:{ afterrender:function(cmp){ cmp.fileInputEl.set({ accept:'audio/*' }); } } } But this code only works the first time I click on "Examine" button, when I click again on it, the restriction

File upload field is reset when submit form

巧了我就是萌 提交于 2019-12-13 14:51:50
问题 I am using ExtJS version 4.1.1. I try to create upload file form using filefield as follow: { xtype: 'filefield', itemId : 'my-file', name: 'my file', emptyText : 'No file chosen', fieldLabel: 'Upload File', submitValue: true, allowBlank : false, buttonText: 'Browse', listeners: { change: function(fld, value) { var newValue = value.replace(/C:\\fakepath\\/g, ''); fld.setRawValue(newValue); } } } When the form is submitted, the filefield is reset. As I see in http://www.sencha.com/forum

How can I replace/override an uploaded file?

非 Y 不嫁゛ 提交于 2019-12-12 13:28:04
问题 I want to be able to upload a file and on each upload to override/replace the existing file with the newest version. from django.core.files.storage import FileSystemStorage fs = FileSystemStorage(location='C:/temp', base_url='/attachments') class Import(models.Model): file = models.FileField(upload_to='data', storage=fs) 回答1: I don't know if this is the best approach, but the following lines helped me override/replace the existing file. upload_dir_path = Setting.objects.get(entry__exact=