GithubHelp home page GithubHelp logo

Comments (9)

DorienD avatar DorienD commented on September 25, 2024

Hmmm when i change the contenttype settings of upload_bio from

upload_bio:
    type: file

to

upload_bio:
    type: image

I don't get the string to array error. But the uploaded image path is not displayed in the image field in the admin.

from boltforms.

DorienD avatar DorienD commented on September 25, 2024

It is not displayed but it is saved to the database. So i guess type:file doesn't support the way the form sends the data to the database.

from boltforms.

DorienD avatar DorienD commented on September 25, 2024

So the data from the form is saved as this in the database:

{"file":"Users/dorien/Projects/bolt/groteprijsnl//Laagje voor laagje.7615ae4d4f2eb7462e251d10.png",
"filename":"Users/dorien/Projects/bolt/groteprijsnl//Laagje voor laagje.7615ae4d4f2eb7462e251d10.png",
"title":"Laagje voor laagje.7615ae4d4f2eb7462e251d10.png",
"basepath":"public/files/uploads"}

When uploading to type:image through the admin the data is saved as this in the database:

{"file":"2020-01/cat-bowtie.jpg"}

When uploading to type:file through the admin the data is saved as this in the databae:

2020-01/1578424192_cat-bowtie.jpg

I'm a bit lost in what kind of field type i should save an upload from boltforms. And how to display this in the admin.

from boltforms.

DorienD avatar DorienD commented on September 25, 2024

If i could access the title and the pasebath from the database then i could make a clickable link to the document. But when trying to display this field {{ record.upload_bio }} i get this Users/dorien/Projects/bolt/groteprijsnl//Laagje voor laagje.7615ae4d4f2eb7462e251d10.png. Not sue if that is the file or the filename. I tried {{ record.upload_bio.title }} but i can't seem to get the title

from boltforms.

DorienD avatar DorienD commented on September 25, 2024

When changing to a database table instead of saving to a contenttype the saved data in the database from file upload looks like this:

/Users/dorien/Projects/bolt/groteprijsnl/public/files/uploads/cat-knudu.d3fa090cfbcc3919c912a802.jpeg

Which is perfect! Why is it saved so different to a contenttype...

from boltforms.

bobdenotter avatar bobdenotter commented on September 25, 2024

@DorienD Looks like that is a slightly different issue.. in the DB it saves the path on the file system, which is different than how an type: image field handles it. If you wish to display it in the site, you probably just need to replace the absolute part of the path.. Try:

<img src="{{ record.upload_bio|replace({'/Users/dorien/Projects/bolt/groteprijsnl/public/': '/'}) }}">

from boltforms.

SvanteRichter avatar SvanteRichter commented on September 25, 2024

@DorienD I think that for saving more complex fields (usually anything that is not a scalar or non-associative array IIRC) then you are better off extending the form with your own fields based on symfony forms.

from boltforms.

DorienD avatar DorienD commented on September 25, 2024

Hmmm I think with the replacing of the absolute part of the path i'm getting really close but!

{{ record.upload_bio|replace({'Users/dorien/Projects/bolt/groteprijsnl//': '/public/files/uploads/'}) }}

Results in this url
http://0.0.0.0:8000/public/files/uploads/Laagje%20voor%20laagje.7615ae4d4f2eb7462e251d10.png

Which i figured would be the right path to access the image, but this gives a 404. So now i think i have to figure out how to access the files folder.

from boltforms.

DorienD avatar DorienD commented on September 25, 2024

Ah! I got it! Set management_controller: true in the boltforms settings and now this works:

{{ record.upload_bio|replace({'Users/dorien/Projects/bolt/groteprijsnl//': '/boltforms/download?file='}) }}

🎉

from boltforms.

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.