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

Version 2.0 #60

Merged
merged 7 commits into from
Sep 8, 2017
Merged

Version 2.0 #60

merged 7 commits into from
Sep 8, 2017

Conversation

codingjoe
Copy link
Owner

  • Remove signing view
    Widgets are now signed when rendered. This behavior saves one
    call to the application server.
  • Add support for accept attribute
    Limit upload policy MIME-Type in accept attribute.
  • Add support for multiple file uploads
  • Remove django-appconf dependency
  • Remove progress bar
  • Add middleware to allow seamless Django integration
  • Add automatical FileField.widget overwrite
  • Add tests
  • Reduce file size
  • Reduce asset size

@codingjoe codingjoe force-pushed the version2 branch 6 times, most recently from 2e85d5f to f2c9d9c Compare August 30, 2017 18:15
@codingjoe codingjoe changed the title Version 2 version 2 Aug 30, 2017
@codingjoe codingjoe changed the title version 2 Version 2.0 Aug 30, 2017
@codingjoe codingjoe force-pushed the version2 branch 6 times, most recently from eabe36c to 9147424 Compare August 30, 2017 22:18
@codingjoe
Copy link
Owner Author

@amureki would you care to review this? I completely rewrote this library.

*   Remove signing view
    Widgets are now signed when rendered. This behavior saves one
    call to the application server.
*   Add support for `accept` attribute
    Limit upload policy MIME-Type in `accept` attribute.
*   Add support for `multiple` file uploads
*   Remove `django-appconf` dependency
*   Remove progress bar
*   Add middleware to allow seamless Django integration
*   Add automatical `FileField.widget` overwrite
*   Add tests
*   Reduce file size
*   Reduce asset size
Copy link

@grunskis grunskis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to get this working in a new test app, but an example app in the repo would be of a great help :)

What I got working is file upload to tmp/ but who's supposed to move the file over to the destination specified in upload_to?

Some other general comments:

  • there's .gitmodule file with references to some jquery plugins
  • would be nice to have a changelog available to see what needs to be upgraded from 1.2.1

README.md Outdated
* no JavaScript or Python dependencies (no jQuery)
* Python 3 and 2 support
* Auto swapping based on your environment
* works just like the buildin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, s/buildin/built-in/

Also it's not entirely clear what's meant by built-in...

README.md Outdated
* lightweight: less 200 lines
* no JavaScript or Python dependencies (no jQuery)
* Python 3 and 2 support
* Auto swapping based on your environment
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me what you mean here

README.md Outdated
### Advanced usage examples
Django does have limited [support to uploaded multiple files][uploading-multiple-files].
S3File fully supports this feature. The custom middleware makes ensure that files
are accessible via `request.FILES`, even tho they have been uploaded to AWS S3 directly
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/tho/though/

README.md Outdated
Django does have limited [support to uploaded multiple files][uploading-multiple-files].
S3File fully supports this feature. The custom middleware makes ensure that files
are accessible via `request.FILES`, even tho they have been uploaded to AWS S3 directly
and not to you Django application server.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/you/your/

README.md Outdated
MyS3FileView.as_view(), name='s3file-sign'),
)
```
S3File uses a strict policy and signature to grand clients permission to upload
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/grand/grant/

class Meta:
model = FileModel
fields = ('file',)
widgets = {'file': AutoFileInput}


class ClearableUploadForm(forms.ModelForm):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This form doesn't seem to be used anywhere and can be removed

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/test_forms.py:85 ;)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, somehow missed that. But actually do you really need these 2 identical forms here?

return unescape(tag.childNodes[0].nodeValue)
(() => {
function parseURL (text) {
console.log(text)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to keep this in?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, thx ;)

README.md Outdated
urlpatterns = patterns(
...
url(r'^s3file/', include('s3file.urls')),
MIDDLEWARE_CLASSES = (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When creating a new Django app the setting is now called MIDDLEWARE and middleware are processed a bit differently. Docs should probably reflect that. In case you want to support both middleware versions (as IMO this library should) then there's https://docs.djangoproject.com/en/1.11/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware

s3file/forms.py Outdated
self.access_key = settings.AWS_ACCESS_KEY_ID
self.secret_access_key = settings.AWS_SECRET_ACCESS_KEY
self.bucket_name = settings.AWS_STORAGE_BUCKET_NAME
self.upload_path = getattr(settings, 'S3FILE_UPLOAD_PATH', os.path.join('tmp', 's3fine'))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you meant tmp/s3file not tmp/s3fine as the default

s3file/forms.py Outdated
'data-policy': force_text(self.get_policy()),
'data-signature': self.get_signature(),
'data-key': self.upload_folder,
'data-s3-url': 'https://s3.amazonaws.com/%s' % self.bucket_name,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://s3.amazonaws.com/ works for us-east-1 and maybe some other regions but didn't work for me for eu-west-1

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dang. can you show me tomorrow?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the list of regions and s3 endpoints: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

I think you would need an extra setting where to specify S3 region for the bucket if you want to support regions other than us-east-1

@codingjoe
Copy link
Owner Author

@grunskis I think that should resolve most issues.
I decided to use boto3's buildin method generate_presigned_post. This makes it a lot easier. I don't have to deal with sining and different bucket setups. As long as the storage works, so does the upload.

@grunskis
Copy link

grunskis commented Sep 8, 2017

Ok, will take a look again.

Copy link

@grunskis grunskis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff! Now works much better :)

@@ -24,6 +24,6 @@
packages=['s3file'],
include_package_data=True,
install_requires=[
'django-appconf>=0.6',
'django-storages',
],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also include boto or boto3 here or document that one of these is required.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well none of this works, if the BotoStorage isn't setup and configured. This usually is the first step. But I will make sure to mention this, in the setup guide. Thanks! having documentation reviewed is always really helpful.

@codingjoe codingjoe merged commit 02ccea9 into master Sep 8, 2017
@codingjoe codingjoe deleted the version2 branch September 8, 2017 18:39
@schwartzmx schwartzmx mentioned this pull request May 21, 2019
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 this pull request may close these issues.

None yet

2 participants