0

I'm having an issue with Django-Filebrowser when I try to upload an image. I'm using the following versions: Django 1.8.7, Filebrowser 3.6.4 and Python 2.7.

When I try to upload an image, everything works as expected, and the uploaded files are placed in the right folder without any problem; but the resultant file url doesn't have any leading slash necessary to serve properly the file.

For example, if I try to upload "test.jpg", the final image url will be "uploads/test.jpg" and "_versions/test_xxx.jpg" that actually creates issues even in the Filebrowser panel, since the resulting request will be issued to http://localhost:8000/admin/filebrowser/browse/uploads/test.jpg and http://localhost:8000/admin/filebrowser/browse/_versions/test.jpg rather than http://localhost:8000/uploads/test.jpg and http://localhost:8000/_versions/test.jpg that the server would serve properly.

(Note that the Filebrowser panel url is http://localhost:8000/admin/filebrowser/)

Here's my settings:

urls.py:

urlpatterns = [
    url(r'^admin/filebrowser/', include(site.urls)),
    url(r'^admin/', include(admin.site.urls)),

    url(r'^', include('pages.urls')),
    url(r'^blog/', include('articles.urls')),

    url(r'^tinymce/', include('tinymce.urls')),
    url(r'^grappelli/', include('grappelli.urls')),
]

settings.py

FILEBROWSER_DIRECTORY = 'uploads/'
FILEBROWSER_VERSIONS_BASEDIR = '_versions/'

Add a leading slash to the FILEBROWSER_DIRECTORY would trigger a SouspiciusFileOperation error since '/uploads/' is located outside the project folder.

Thanks in advance.

Marco Ferrantini
  • 381
  • 2
  • 10

1 Answers1

0

Finally I've got the point. It's enough to set explicitly MEDIA_ROOT and MEDIA_URL:

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

Now Filebrowser will search for "uploads/" and "_versions/" folders in this new parent one, so "/media" needs to be served accordingly.

Marco Ferrantini
  • 381
  • 2
  • 10