filepicker / filepicker-django Goto Github PK
View Code? Open in Web Editor NEWA django plugin to make integrating with Filepicker.io even easier
License: Other
A django plugin to make integrating with Filepicker.io even easier
License: Other
I have an FPUrlField within a Django admin inline model which works fine at first. However, when clicking on "add another" below the currently visible inlines, the newly appearing "Pick File" button does not pop up the Filepicker panel as expected. Instead, it submits the form and saves the model.
I'm guessing that Filepicker's JS API only adds the "Pick File" button's click event handler when it's visible on first page load. Since the additional forms that the Django admin adds are invisible at first, the event handler doesn't get attached and the button ends up working as a regular "submit" button.
I'm not sure how to solve this. Maybe adding a method to the JS API that makes it go through all widgets again and re-attach the event handler?
Since the FPFileField
requires an upload_to
parameter, that can't be empty or "/"
, and the Filepicker service uploads to the root of my bucket (I don't see anywhere to configure this through the UI), how do I access the file?
With a model field like the one below, I get headshot.url
as /uploads/file_name.ext
, instead of the filename generated by filepicker.
headshot = FPFileField(blank=True, upload_to='uploads')
What is the default implementation for django_filepicker and s3?
I see that you added default support for South (3bf5171) a few months ago. Nice work! Is there any reason this hasn't been pushed to PyPI?
On class based update form,
when the field is required,
because filepicker doesn't retrieve the file you have to send it back ...
i think it's not good
Probably due to the lack of updates, the CONVERT service with features mentioned here does not work.
The service is recognized as a valid service, but the convert options do not show up when uploading a picture.
I'm not so bright....... so i wasted half an hour wondering why the widget wasn't working before i realized i need to manually include the filepicker.io js file at the end in my template for the widget to work.
<script type="text/javascript" src="//api.filepicker.io/v1/filepicker.js"></script>
Might be worth mentioning in the instructions for slow people like me.
I'm sure I've overlooked something here, but I'm using s3, and everything is uploading correctly. However, when I try to retrieve the file with something like...
<img src="{{ model.fpfile.url }}">
it's returning the s3 url, but without the unique id.
The README.md example was almost good enough to run with; However, it didn't mention the two needed changes to settings.py: The inclusion of a FILEPICKER_API_KEY variable, and the addition of the filepicker middleware. The error messages you'll see when trying to integrate the code will point these out -- but it would have saved a few minutes of digging through the demo-project's code if this information were provided up-front.
Cheers!
I'm seeing a problem where FilepickerFile.get_file
returns the Python file
object wrapped in a Django File
object. At that point, FilepickerFile
is not needed, but the Django File
might yet get passed around.
While the Django File
is being used, the FilepickerFile
object is dropped from context and gets garbage collected. It promptly closes the Python file
and deletes the temporary file.
Unfortunately, that was the file descriptor that the Django File
is still using, which leads to errors about trying to read from a closed file: ValueError: I/O operation on closed file
.
FilepickerFile
really has no reason to track the Python file
other than to close it, but Django File
should take care of that.
FilepickerFile
does need a temporary file, but it doesn't need to delete the file itself. Ideally, one would use os.tmpfile
or something from the tempfile
module, which will take care of deleting the file from the FS after all file descriptors have been closed (e.g. Django File
is all done with the python file
).
If both changes were made, FilepickerFile
wouldn't need any cleanup at all, nor would it interfere with the Django File
it spawns from FilepickerFile.get_file()
.
Unfortunately urllib
doesn't offer any way to download into a file-like object, it can only download into filenames. It doesn't seem clear how to download into a pre-opened temporary file using urllib or urllib2.
The third party requests
library is a great replacement for urllib*
. This would be the thing to use with a Python-maintained temporary file: http://docs.python-requests.org/en/latest/user/quickstart/#raw-response-content
This is a small thing but somewhat annoying: everytime I do an pip install -U django-filepicker
, it tries to upgrade Django as well. This seems to be because in setup.py
it says
install_requires=['django']
Can we assume that anyone using django-filepicker has Django installed? That would make upgrading with pip go much more smoothly...
The Filepicker URL needs policy and signature attached as query parameters when such security policies are in effect.
I already rewrote to_python
in FPFileField
to make use of self.additional_params
in my local copy, which I can submit as a pull request.
Ideally this code would go into utils.FilepickerFile.get_file
as per #23, but that utility does not have access to the additional parameters found in FPFileField
. They'll have to be parameters somewhere.
(slightly different than #29 )
We currently have our image model as models.FPFileField. The issue we ran into is when people upload via dropbox and then move/delete their image in dropbox, it disappears from our site. Someone at Ink told us to setup S3 and then use the pickAndStore method to place those files in S3 so they are no longer links to Dropbox.
The response to #29 is to use FPUrlField which is in forms not models. It is implied that FPFileField store the image locally and remotely while FPUrlField just stores remotely(S3). I don't think any of the images are actually being stored locally in our case as they are all filepicker links (which in the case of dropbox are merely references).
I'm sorry if I sound clueless as I am trying to wrap my head around filepicker and it's implementation at our site. I basically need to know, once I setup our FilePicker account to use S3, how to emulate the pickAndStore functionality so all new pictures picked by customers are stored at S3 and the links stay good regardless of what happens to the original image.
Thanks!
Retrieving a file from Filepicker is written in two different places. Appears to be copy/paste.
It seems like FPFileField.to_python
should be rewritten something like this:
def to_python(self, data):
try:
fd = FilepickerFile(data)
except ValueError, e:
if 'Not a filepicker.io URL' in str(e):
# return None if data isn't a valid Filepicker URL
return None
else:
# otherwise pass the buck
raise e
else:
return fd.get_file()
The else
s in the above code are not strictly necessary.
I'm getting this error in my application every time I try to upload a file (0.2.2):
File "/django_filepicker/utils.py", line 62, in get_file
file = File(tmp, name=name)
UnboundLocalError: local variable ‘name’ referenced before assignment
I suppose I am getting this because neither the X-File-Name
nor Content-Disposition
headers are being set by the application.
The thing is I'm not sure why, can you shed me a light?
Also, maybe that's something you wanna protect from, like having a default for the name
variable maybe?
Thanks!
Django now fully supports Python 3, but this plugin does not, and setup.py does not specify supported versions. As a result, this plugin will install but crash if Python 3 is used.
According to the 2to3 tool, Converting the plugin to support Python 3 will involve at least the following:
import models
to from . import models
urllib
and urllib2
to the new urllib
modules and submodulesexcept ValueError, e:
to except ValueError as e:
... and some other small changes.
It should be possible to support python 2 and python 3 simultaneously.
Whenever I take the demo, and run it on my local server, I can pull up the upload dialoge, but it keeps throwing a javascript error when i select the file to upload:
Uncaught Error: SecurityError: DOM Exception 18
Which then freezes the page at a spinning uploading screen. My API key has been entered as well.
I am using django_filepicker.models.FPFileField() model field. When I upload image and hit save I get the following error: [Full Traceback]
I'm working with a codebase which specifies data-fp-extensions
.
FilepickerException: Error: Cannot pass in both mimetype and extension parameters to the pick function
I have specified FPFileField.mimetypes
to be nothing, None
, ''
, (,)
, and always it comes back */*
. So then I read the code and figured out why:
https://github.com/Ink/django-filepicker/blob/0671c4315b61f897358367a757b6ef8444aa183b/django_filepicker/forms.py#L33
Please specify at least one condition in which mimetypes may be left blank.
On the one hand, you could explicitly check to see if 'data-fp-extensions' in additional_params
, in which case mimetypes should not be included.
On the other hand, there might be other instances where mimetypes cause a problem. It might be hard to find all those edge cases. Perhaps add a constant NoMimetypes = object()
singleton into forms.py, and do not include mimetypes if mimetypes == NoMimetypes
.
Is there currently a suggested to handle multiple files with django? My app calls for this and I am thinking the easiest way may be to have a model for the InkBlob that points back to the related model.
I'm thinking of hooking into the success callback and then taking care of the FK with some ajax.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.