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

File upload broken #34

Closed
schliflo opened this issue Oct 14, 2019 · 11 comments
Closed

File upload broken #34

schliflo opened this issue Oct 14, 2019 · 11 comments
Assignees
Labels
bug Something isn't working fixed Issue has already been fixed

Comments

@schliflo
Copy link
Contributor

schliflo commented Oct 14, 2019

File upload fails with Undefined index: name:
Screenshot 2019-10-14 at 22 55 52

user/blueprints/flex-objects/slides.yaml:

title: Slides
description: Slides for slideshows
type: flex-objects

config:
  admin:
    list:
      fields:
        header.title:
          link: edit
  data:
    object: 'Grav\Plugin\FlexObjects\Types\FlexPages\FlexPageObject'
    collection: 'Grav\Plugin\FlexObjects\Types\FlexPages\FlexPageCollection'
    index: 'Grav\Plugin\FlexObjects\Types\FlexPages\FlexPageIndex'
    storage:
      class: 'Grav\Framework\Flex\Storage\FolderStorage'
      options:
        formatter:
          class: 'Grav\Framework\File\Formatter\MarkdownFormatter'
        folder: 'user-data://slides'
        pattern: '{FOLDER}/{KEY}/default.md'
form:
  validation: loose

  fields:
    header.img:
      label: Slide Image
      help: The image used for in the slide
      type: file
      size: full
      style: vertical
      multiple: false
      destination: 'user://pages/images/'
      accept:
        - 'image/*'

    header.title:
      type: text
      autofocus: true
      style: vertical
      label: PLUGIN_ADMIN.TITLE

    content:
        type: markdown
        validate:
          type: textarea
@mahagr
Copy link
Contributor

mahagr commented Oct 16, 2019

I've reproduced the issue.

@mahagr mahagr self-assigned this Oct 16, 2019
@mahagr mahagr added the bug Something isn't working label Oct 16, 2019
@mahagr
Copy link
Contributor

mahagr commented Oct 16, 2019

The issue is not fully fixed but goes over the error.

In the mean time, please use this blueprint (updated for the upcoming version):

title: Slides
description: Slides for slideshows
type: flex-objects

# Flex configuration
config:

  # Administration Configuration
  admin:
    # Admin menu
    menu:
      list:
        route: '/slides'
        title: Slides
        icon: fa-address-card-o
        # Authorization to be able to see the menu item
        authorize: ['admin.pages', 'admin.super']
        # Priority -10 .. 10 (highest goes up)
        priority: 2

    # Admin template type (folder)
    template: default

    # List view
    list:
      # Fields shown in the list view
      fields:
        header.title:
          link: edit
          search: true
      # Extra options
      options:
        # Default number of records for pagination
        per_page: 20
        # Default ordering
        order:
          by: title
          dir: asc

    edit:
      title:
        template: "{{ form.value('header.title') }}"

  # Site Configuration
  site:
    templates:
      collection:
        # Lookup for the template layout files for collections of objects
        paths:
          - 'flex/{TYPE}/collection/{LAYOUT}{EXT}'
      object:
        # Lookup for the template layout files for objects
        paths:
          - 'flex/{TYPE}/object/{LAYOUT}{EXT}'
      defaults:
        # Default template {TYPE}; overridden by filename of this blueprint if template folder exists
        type: slides
        # Default template {LAYOUT}; can be overridden in render calls (usually Twig in templates)
        layout: default

  # Data Configuration
  data:
    # Object class to be used, allowing custom methods for the object
    object: 'Grav\Common\Flex\Types\Generic\GenericObject'
    # Collection class to be used, allowing custom methods for the collections
    collection: 'Grav\Common\Flex\Types\Generic\GenericCollection'
    # Index class to be used, works as a quick database-like lookup index
    index: 'Grav\Common\Flex\Types\Generic\GenericIndex'
    storage:
      # Storage class, if you want to have associated assets, such like images, use FolderStorage
      class: 'Grav\Framework\Flex\Storage\FolderStorage'
      options:
        formatter:
          # File formatter class, in this case the file is stored in markdown
          class: 'Grav\Framework\File\Formatter\MarkdownFormatter'
        # Folder where all the objects will be stored
        folder: 'user-data://slides'
        # File pattern to generate the filename
        pattern: '{FOLDER}/{KEY}/{FILE}{EXT}'
        # Filename
        file: slide
        # Field which will be used as {KEY}
        key: storage_key
        # Keep index file in filesystem to speed up lookups
        indexed: true
    search:
      # Search options
      options:
        contains: 1
      # Fields to be searched
      fields:
        - header.title

# Regular form definition
form:
  validation: loose

  fields:
    header.img:
      type: file
      label: Slide Image
      help: The image used for in the slide
      size: full
      style: vertical
      multiple: false
      accept:
        - 'image/*'

    header.title:
      type: text
      autofocus: true
      style: vertical
      label: PLUGIN_ADMIN.TITLE

    markdown:
      type: markdown
      validate:
        type: textarea

EDIT: updated to use GenericObject

@schliflo
Copy link
Contributor Author

very cool to see the extra menu items! while this does not completely solve the issue i have, it's a lot better already! thank you for your help. I'm looking forward to the new release :)

@chesjon
Copy link

chesjon commented Nov 9, 2019

I installed the latest version today and am having an issue with the file type. When creating or editing a flex object I choose an image and it saves without any errors or warnings. The file doesn't appear to be uploaded and the image field in the markdown file does not have a value.

I am wondering if the problem I am describing is related to this issue or if I am doing something wrong. I tried using the blueprint provided by @mahagr to make sure it wasn't just an issue with my blueprint.

@schliflo
Copy link
Contributor Author

schliflo commented Feb 3, 2020

The issue still persists in RC5 (no error, file does not get saved). Do you think this will get fixed in time for the final release @mahagr ?
Either way I'd suggest closing this issue (labeled bug) or #37 (labeled enhancement) -otherwise they seem to be the same.

@juleeho
Copy link

juleeho commented Apr 18, 2020

I am facing this issue too, @mahagr why in your blueprint it's missing the destination option under the header.img field? Just asking.
Thanks

@mahagr mahagr added the fixed Issue has already been fixed label Jun 4, 2020
@mahagr
Copy link
Contributor

mahagr commented Jun 4, 2020

Should be fixed. @ricardo118 Can you test it out?

@ricardo118
Copy link
Collaborator

@mahagr using the blueprint above I get

without using a destination, no save happens for the object.

Using a destination like destination: data://slides/images I get

The object saves with

---
title: title
img: {  }
---

slide content

@mahagr mahagr added fixed Issue has already been fixed and removed fixed Issue has already been fixed labels Jun 5, 2020
@mahagr
Copy link
Contributor

mahagr commented Jun 5, 2020

Updated the blueprint again and fixed the bug in Grav. Thanks for testing, now it really works.

@clivebeckett
Copy link

Updated the blueprint again and fixed the bug in Grav. Thanks for testing, now it really works.

@mahagr I reckon this will work with the next Release Candidate? I’m on Admin v1.10.0-rc.11 which was released three weeks prior to your comment here.

I copied the above pasted blueprint and everything works except the file upload – no matter whether I added a destination to the file field definition or not.

@rhukster
Copy link
Member

rhukster commented Jun 7, 2020

@mahagr addressed file uploads in an independent branch of grav. It’s a big change to unify and cleanup the logic and has not been merged yet.

https://github.com/getgrav/grav/tree/feature/1.7-media

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Issue has already been fixed
Projects
None yet
Development

No branches or pull requests

7 participants