Keep getting an error when trying to save a file

I’m trying to save an uploaded file to the following folder : grav\grav-admin\user\plugins\testing

This is my code :
custom_file:
name: myfile
type: file
label: A label
destination: ‘plugins://testing’
multiple: true
autofocus: false
accept:
- image/*

However, I end up getting this error message :
“copy(plugins://testing/11_essais_racisme.jpg): Failed to open stream: "RocketTheme\Toolbox\StreamWrapper\ReadOnlyStream::stream_open" call failed”

Am I doing something wrong ?

1 Like

It looks like you are following the example in the docs closely.

The first clue I notice is in the error message: “ReadOnlyStream”. What are the file permissions on the folder where the plugin sits? Are you using shared hosting? Please tell us more about your setup, it seems like a setup issue. The error seems to be originating from the operating system.

Also, try another destination and let us know how you go.

1 Like

@hughbris, I wonder if this has ever worked…

See feature request Allow streams in file field widget #119 and the merged commit.

Using the $locator, the destination in the form is tested whether it is a valid stream (line 623) , but the stream is not being translated into a valid path. Hence the Form plugin tries to save to folder plugins://tester.

When I add at line 626 of the commit the following to translate the stream into a path:

$destination = $locator->findResource($destination);

The file is correctly saved.

Note however, that the destination folder must exist.

2 Likes

Here’s the root

I tried changing the destination, but whatever I do, it keeps trying to save in this folder.

I also tried to save it localy, but always keep getting the same error.

e.g.
“copy(plugins://testing/xzy.png): Failed to open stream: "RocketTheme\Toolbox\StreamWrapper\ReadOnlyStream::stream_open" call failed”

I just assumed it must have worked. The plugins:// stream did seem slightly surprising though.

(Sorry I don’t always have time to set up tests. Well, a lot of them seem simple but I fear going down rabbit holes.)

I do know that I set up a stream file destination in a front end form just in the last week. I used user-data://... and it worked well.

I never quite understood the reasons why the same field type can be different in front end and blueprints, or why some of the useful blueprint fields can’t be available to front end forms. They seem to be from different parts of the codebase but I haven’t ventured down that potential rabbit hole either.

I know you like to investigate these questions, @anon76427325, so please report back if you feel like it :slight_smile:

1 Like

@hughbris, Forget what I said before, the rabbit hole is deeper than I thought…

It seems functions like mkdir and others, have been wrapped (never knew that was even possible) by Grav. I just assumed that mkdir('plugins://tester') had to fail, but under the hood, the wrapper translates the stream into a path which is recognisable by the native mkdir function.

However, the wrapper doesn’t seem to look up the stream in the list of all steams (in which plugins:// is defined), but in some cache (no I didn’t dive in any deeper). Stream user-data:// does exist in that cache, but plugins:// (or user://) doesn’t.

Bottom line: Stream plugin:// will not work. But I’ve been fooled before though…

3 Likes