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

Accessing file url #29

Closed
pasevin opened this issue Jan 14, 2020 · 4 comments
Closed

Accessing file url #29

pasevin opened this issue Jan 14, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@pasevin
Copy link
Contributor

pasevin commented Jan 14, 2020

I'm back :) Happy New Year!

I'm almost finished with integrating this library into my project.
One last thing which I'm confused about is how do I access the url of the StoredUpload.

I can see that TemporaryUpload has a file = models.FileField, but StoredUpload has only file_path = models.CharField. This means I can't access obj.file_path.url.

Am I missing something? Or is this a bug?

Cheers

@jcohen02
Copy link
Collaborator

Happy New Year to you too :-)

Are you trying to access the URL so that you can call the file on the client side?

If you want to load a stored upload on the client side, then you could use the load endpoint from the filepond API - django-drf-filepond supports load and restore.

For example, if you upload a file (the initial temporary upload) and you get an ID back for your uploaded file of ABCDEFGH, once you have subsequently used the django-drf-filepond API to store the file, you can get access the stored upload by making an HTTP GET request to /fp/load/?id=ABCDEFGH and the uploaded file will be returned.

There is also a restore endpoint for working with temporary uploads. If you use restore or load to try and access a file ID that doesn't exist, you'll get a 404.

The alternative option would be to add a view into your own app using a URL pattern of your choice and then within the view implementation, use the provided file_path attribute on the StoredUpload object to get the path of the file on disk and return it to the client.

On the server side, you should be able to create the path to the stored file by joining the value of DJANGO_DRF_FILEPOND_FILE_STORE_PATH from the app settings with su.file_path where su is a StoredUpload instance.

Hope that helps and answers the question.

@jcohen02 jcohen02 self-assigned this Jan 14, 2020
@jcohen02 jcohen02 added the question Further information is requested label Jan 14, 2020
@pasevin
Copy link
Contributor Author

pasevin commented Jan 15, 2020

Yes I am using load and restore endpoints on my client when using Filepond javascript interface.

But there's a case when I need to display uploaded pictures on the website with related posts. I need an actual web url, which I can insert into html, not a server path.

Usually I use FileField or ImageField to get direct web url like: http://eu-west-1.hypeapp.media.s3.amazonaws.com/uk/london/east/events/photos/archive/20130916180320_mobile.jpg.

This is what I'm talking about: https://docs.djangoproject.com/en/3.0/ref/models/fields/#django.db.models.fields.files.FieldFile.url

Hope that makes more sense.

@pasevin
Copy link
Contributor Author

pasevin commented Jan 16, 2020

I've solved my predicament this way: #30

If you don't see any issues with this, you can merge it :)

@jcohen02
Copy link
Collaborator

Many thanks and apologies for not responding sooner to your previous response. Your fix looks good. While this doesn't seem to introduce breaking changes from the API perspective, the DB update means that I think there should be a major release to include this change. I'm planning a 0.4.0 release with a few other fixes and this will be included in that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants