Skip to content
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

Doesn't seem to work with Amazon S3 #7

Open
iranana opened this issue Mar 14, 2013 · 7 comments · May be fixed by #27
Open

Doesn't seem to work with Amazon S3 #7

iranana opened this issue Mar 14, 2013 · 7 comments · May be fixed by #27

Comments

@iranana
Copy link

iranana commented Mar 14, 2013

Hello, I've been using this app in development and it works wonderfully if you store ajax-uploaded data locally. However, I just deployed a site that uses an Amazon S3 storage bucket and it doesn't play nice with Amazon S3. It thrown me a AjaxUploadException: File path not allowed error. Just a heads up :) Will look into how this package: https://github.com/GoodCloud/django-ajax-uploader handles S3 storage in the meantime. Thanks for the awesome package!

@iranana
Copy link
Author

iranana commented Mar 14, 2013

Is there any possibility someone could look into enabling S3 storage? Just looking at the other package I'm not sure I like their implementation. I much prefer the transparency of this app - any help on fixing this issue would be greatly appreciated as this app is exactly what I'm after. Thanks!

@zmathew
Copy link
Owner

zmathew commented Mar 15, 2013

Thanks for your feedback. I can look into it, but it might be beyond the scope of what this application should be doing.

Are you currently using any custom s3 file storage extension for Django? For example, https://bitbucket.org/david/django-storages/
I'm just wondering how you have integrated S3 into Django.

@iranana
Copy link
Author

iranana commented Mar 15, 2013

Yes I'm currently using django-storages and I get the feeling I'm also
using django-boto. I'm away from my work machine at the moment so I can't
check but I'll post back later with the full configuration. I'm using S3
because I've found that pushing/pulling to the elastic beanstalk with git
is tricky if you store data locally - git seems to have an 'all or nothing'
approach and so if I'm to use local storage I have to export and import my
data every time I do an update. Thanks for your help!

On Sat, Mar 16, 2013 at 7:59 AM, Zach Mathew notifications@github.comwrote:

Thanks for your feedback. I can look into it, but it might be beyond the
scope of what this application should be doing.

Are you currently using any custom s3 file storage extension for Django?
For example, https://bitbucket.org/david/django-storages/
I just wondering how you have integrated S3 into Django.


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-14978875
.

@alexlovelltroy
Copy link

I went to widgets.py to try and help with this and got in over my head fairly quickly, but I found settings.MEDIA_URL on line 22. With storages, settings.MEDIA_URL might not be the right thing to use here. At least for the existing image (if there is one), field.url should be used instead.

@iranana
Copy link
Author

iranana commented Apr 11, 2013

I've not found a solution to this issue yet, unfortunately. I'm using django-storages and django-boto to upload media to an S3 bucket. I'm using the following options in my settings.py... any ideas?

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
THUMBNAIL_DEFAULT_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = '...'
AWS_SECRET_ACCESS_KEY = '...'
AWS_STORAGE_BUCKET_NAME = '...'

MEDIA_ROOT = '/media/'
MEDIA_URL = 'http://s3.amazonaws.com/...'

@iranana
Copy link
Author

iranana commented May 6, 2013

Has anyone had some time to look into this? I was playing around with things today but to no avail. I've included a traceback below. When I select an image it does actually upload it to my S3 bucket (I've deleted the images though, so the url in the traceback won't actually work) but something goes awry. The img tag is not created and then when hitting upload I'm thrown the following error. Seems like it's close to working but it can't sanitize the url properly or something.

Traceback (most recent call last):

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/views/generic/base.py", line 48, in view
    return self.dispatch(request, *args, **kwargs)

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/utils/decorators.py", line 25, in _wrapper
    return bound_func(*args, **kwargs)

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/contrib/auth/decorators.py", line 20, in _wrapped_view
    return view_func(request, *args, **kwargs)

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/utils/decorators.py", line 21, in bound_func
    return func(self, *args2, **kwargs2)

  File "/opt/python/current/app/imagestore/views.py", line 212, in dispatch
    return super(CreateAJAXImage, self).dispatch(*args, **kwargs)

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/views/generic/base.py", line 69, in dispatch
    return handler(request, *args, **kwargs)

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/views/generic/edit.py", line 172, in post
    return super(BaseCreateView, self).post(request, *args, **kwargs)

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/views/generic/edit.py", line 137, in post
    if form.is_valid():

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/forms/forms.py", line 124, in is_valid
    return self.is_bound and not bool(self.errors)

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/forms/forms.py", line 115, in _get_errors
    self.full_clean()

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/forms/forms.py", line 270, in full_clean
    self._clean_fields()

  File "/opt/python/run/venv/lib/python2.6/site-packages/django/forms/forms.py", line 281, in _clean_fields
    value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))

  File "/opt/python/current/app/ajax_upload/widgets.py", line 54, in value_from_datadict
    raise AjaxUploadException(u'%s %s' % (_('File path not allowed:'), file_path))

AjaxUploadException: File path not allowed: https://aspacebetween-media.s3.amazonaws.com/ajax_uploads/c3178faa9ef648a78727e3033c80107d-209025_10151107767827670_2065077431_o.jpg?Signature=xVp%2B4jT%2B0vcrrk%2Fz1DFfLwDu0EQ%3D&Expires=1367814670&AWSAccessKeyId=AKIAIFA7EOMOBZD3HYBA

@kartikdanidhariya
Copy link

I have also same problem ,
Any solution !!!

leifdenby added a commit to leifdenby/django-ajax-upload-widget that referenced this issue Oct 7, 2015
Fixes zmathew#7

If `MEDIA_URL` was set to `http://...` then the uploader would fail
because the returned path from Amazon S3 is `https://..`. This commit
fixes this by using `urlparse` instead to match the hostname and find
the relative path.
@leifdenby leifdenby linked a pull request Oct 7, 2015 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants