GithubHelp home page GithubHelp logo

Comments (5)

m29h avatar m29h commented on June 3, 2024

I think the function that you are looking for is already there..
record_service.py:59

from pocketbase.

regisin avatar regisin commented on June 3, 2024

I'm trying to use that existing method like this:

    client = PocketBase(settings.PB_URL)
    client.admins.auth_with_password(settings.USERNAME, settings.PASSWORD)
    record = client.collection("example").get_one(item_id)
    record_path = client.get_file_url(record, item.avatar, {})

But I get TypeError: quote_from_bytes() expected bytes. I'm not sure where the issue could be.

from pocketbase.

paulocoutinhox avatar paulocoutinhox commented on June 3, 2024

I think that you have problems with strings and bytes.

Check if something is b"something" where you have strings.

from pocketbase.

regisin avatar regisin commented on June 3, 2024

Looks like the exception comes from urllib. And it's triggered by client.py:123.

Could the fact that get_one() returns a BaseModel and not a Record type be the issue? get_file_url() expects a Record type as the first argument.

from pocketbase.

m29h avatar m29h commented on June 3, 2024

The TypeError exception in urllib occurs if the quote function receives a list urllib.quote(["file.txt"]) and not a string urllib.quote("file.txt")
Your item.avatar is probably a list because pocketbase file type record fields can (potentially) store multiple files and therefore the record field value is always a python list type.

So a to get what you want you need to index the first element of item.avatar to get the explicit file name string.

    record_path = client.get_file_url(record, item.avatar[0], {})

Pocketbase performs analogous to the official JavaScript client example which is also indexing the file record list to get the explicit file name.

const firstFilename = record.documents[0];

from pocketbase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.