-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should StoredUpload use a base FileSystemStorage object based on FILE_STORE_PATH? #31
Comments
Thanks, will do as soon as I can. |
@jcohen02 everything seems to be working fine! |
Great! Many thanks @pasevin. |
I've spoken too early. There's a bug in your code:
|
I'm getting |
I'm investigating - this should have been covered in the tests so while what you're saying does look correct, I'm just checking this out because the tests were passing... |
…eLondon#31" This reverts commit 40fb867.
Thanks for spotting this @pasevin. I've fixed the issue and added a test (which should have been there already!) to cover this. Update committed to |
Hey, I'm still getting an error with this implementation. When I try to present my uploaded files in django admin and via template on my custom page, I get file not found error, because for some reason django is trying to access the file from my local media directory. I have no Not sure if I'm doing something wrong here, but before |
I think @deconstructible
class FilePondStoredSystemStorage(FileSystemStorage):
"""
Subclass FileSystemStorage to prevent creation of new migrations when
using a file store location passed to FileSystemStorage using the
location attribute. Instead the location is applied dynamically on
creation of the subclass avoiding detection of changes by the migration
system.
Addresses #13. Fix is based on fix for similar issue in
https://github.com/julen/pootle/commit/fd7800050172549e9f31544843b986691290ddc2
"""
def __init__(self, **kwargs):
kwargs.update({
'location': FILEPOND_FILE_STORE_PATH,
})
super(FilePondStoredSystemStorage, self).__init__(**kwargs) somehow should take into account the case when remote storage is used, but I'm not clear yet how. You subclass |
Sorry to hear this is still causing issues. I think this must be a result of switching from using a string for the The use of a string provided a straightforward way of representing the file path that was agnostic to the storage medium. However, I think you said the use of a I don't think using a Let me know what you think. |
Hmm... this is getting a little bit too complicated for me right now. I'm on a tight deadline on my own project right now. I will try to find time to give this a thought as soon as I can. |
I couldn't find anything helpful in From the top of my head: from django.core.files.storage import default_storage
FILEPOND_STORAGES_BACKEND = getattr(local_settings, 'STORAGES_BACKEND', None)
stored_storage = default_storage if FILEPOND_STORAGES_BACKEND \
else FilePondStoredSystemStorage |
I've taken another look at this and I think I see what's causing the issues here. We're trying to use a Presumably when a The actual storage of the file seems to be working OK because this is just storing a string representing a path - in fact this is probably wrong, or at least not very clear, and is a leftover from before the I guess when you remove I'm going to run through this again to make sure any fix takes into account both local and remote storage - I'll get this fixed and rolled out tomorrow. |
Yes, this is exactly what is happening. Thanks for being so responsive on this issue! |
No problem, just looking at the best way to be able to dynamically select the storage backend - I'm wondering if a custom storage backend class might be the way to go. This will then look up what type of storage backend we're using and hand off the file storage or retrieval to the relevant backend. I think one issue that we encountered previously here is that you can't access dynamic application settings in the models since the app has not been fully initialised at this stage. I think a custom storage backend will work around this. |
…load and the underlying file storage used by FileField.
Ok, so I think the latest updates should resolve this. If you could test the code, that would be fantastic. The updates are in the PR #36 and the (new) I've set the default storage for I've tested it with storing and loading both binary and text data with a local storage backend and a remote S3 backend. Both worked successfully for me but it would be great if you can test and verify if this resolves the issues. One concern I have is whether this might re-introduce the previous issue we had with new migrations being created due to the dynamic storage location of the different backends. A new migration has been added to add the new storage backend class as the storage class for |
Looks good to me, and it Fixes #34 as well in a better way I guess :) So far no crashes on my set up with remote storage. |
Hi, I've tried to install this branch on a clear machine today and noticed Django output:
If I do that, it creates a new migration inside package: class Migration(migrations.Migration):
dependencies = [
('django_drf_filepond', '0007_altered_stored_upload_file'),
]
operations = [
migrations.AlterField(
model_name='storedupload',
name='file',
field=models.FileField(max_length=2048, storage=storages.backends.s3boto3.S3Boto3Storage(), upload_to=''),
),
] I see your migration 0007 is: class Migration(migrations.Migration):
dependencies = [
('django_drf_filepond', '0006_permupload_mods'),
]
operations = [
migrations.AlterField(
model_name='storedupload',
name='file',
field=models.FileField(max_length=2048, storage=django_drf_filepond.models.FilePondLocalStoredStorage(), upload_to=''),
),
] Shouldn't it be: field=models.FileField(max_length=2048, storage=django_drf_filepond.models.DrfFilePondStoredStorage(), upload_to=''), |
Hi, yes, I agree the migration doesn't look right. In fact, I think there must have been some confusion with this on my part so apologies for that - my build directory seemed to end up with two 0007 migrations in it, one of which specifies I note, however, that if I delete the 0007 migration and then recreate with One thing I can't do is to get it to tell me that the models have changed, as per the message at the top of your previous comment. Can you highlight the steps you're using to get this? I have a test application (based on the tutorial in the docs that I'm using to test this. If I delete the test application's database altogether and then (running in a virtualenv) delete I can switch my app configuration back and forth between the S3 backend and local file storage and delete and recreate the DB (and reinstall the library) each time and it never tells me the migrations are out of date. It would be useful to be able to recreate this so I can see if I can find a better solution, or at least verify for sure whether this has been resolved. |
Looks like the latest commit fixed the issue with I can't remember now, at which point I saw this I will let you know if I notice any other issues regarding this :) |
Thanks for that, sorry that this hasn't been a straightforward fix! Hopefully the issue is now resolved - I'll leave this open for now, I'm intending to do some further tests prior to the next release. |
No problem, I really appreciate you being so active with this project! Keep up the good work :) |
The updates related to this issue are included in v0.3.0. For now, I'll leave this open for a little while in case there are any further problems relating to this. |
This has been present in v0.3.0 for some time now so I'm going to close this issue but please re-open if there are any further issues relating to this. |
The update merged in #30 and discussed in #29 replaces the string used to specify the location of a stored upload with a
FileField
object.At present there is no specific
FileSystemStorage
object set for thisFileField
so it's using the default storage object.Since users of the library will set
DJANGO_DRF_FILEPOND_FILE_STORE_PATH
in their application settings to define the base location of the file store for stored uploads, having a FileSystemStorage object relative to this location should enforce that uploads are stored below this location and may be beneficial from a security perspective?@pasvein, I'm fixing the tests to take account of the changes to the
StoredUpload
model and adding in this alteration. I'll raise a PR just for this fix initially and it would be great if you can check that this doesn't cause any issues for your use case.Thanks.
The text was updated successfully, but these errors were encountered: