Skip to content

Unable to upload files in Forms #2205

@derekjones

Description

@derekjones

Bug Description

I am unable to upload a file in a Form that is using an Asset field in its blueprint.

handle: patch_image
field:
    mode: list
    container: submissions
    restrict: true
    allow_uploads: true
    max_files: 1
    type: assets
    localizable: false
    listable: hidden
    display: 'Patch Image'

When using a single file input:

<input type="file" name="patch_image" id="patch_image" required="required">

The following form errors are produced:

The Patch Image must be an array.
The Patch Image may not have more than 1 items.

Removing the max files requirement gets rid of the second error, but not the first.

When using a multi-file input:

<input type="file" name="patch_image[]" id="patch_image" required="required" multiple>

An exception is thrown on the POST request:

Call to undefined method Statamic\Assets\AssetRepository::create()
#0 /vendor/statamic/cms/src/Forms/Uploaders/AssetUploader.php(34): Illuminate\Support\Facades\Facade::__callStatic('create', Array)
#1 /vendor/statamic/cms/src/Forms/Uploaders/AssetUploader.php(18): Statamic\Forms\Uploaders\AssetUploader->createAsset(Object(Illuminate\Http\UploadedFile))
#2 [internal function]: Statamic\Forms\Uploaders\AssetUploader->Statamic\Forms\Uploaders\{closure}(Object(Illuminate\Http\UploadedFile), 0)
#3 /vendor/laravel/framework/src/Illuminate/Support/Collection.php(638): array_map(Object(Closure), Array, Array)
#4 /vendor/statamic/cms/src/Forms/Uploaders/AssetUploader.php(19): Illuminate\Support\Collection->map(Object(Closure))
#5 /vendor/statamic/cms/src/Forms/Submission.php(144): Statamic\Forms\Uploaders\AssetUploader->upload()

Removing the max files requirement in this context has no change in behavior.

How to Reproduce

Create a Form with an Asset field in its Blueprint. Try to submit the Form on the front end with a file upload.

Extra Detail

Related, the documentation appears to reference an older way of uploading files, which doesn't use blueprints and references types that don't exist.

Environment

Statamic version: v3.0.0-beta.43

PHP version: 7.3.12

Install method (choose one):

  • Fresh install from statamic/statamic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions