Getting "Undefined array key \"name\" message on PUT request to /api/attachments #4274

Closed
opened 2026-02-05 08:23:58 +03:00 by OVERLORD · 1 comment
Owner

Originally created by @MQuillian on GitHub (Oct 20, 2023).

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

When attempting to update an attachment using the API, the update fails with the following response message:
{"error":{"message":"Undefined array key \"name\"","code":500}}

My initial searching returned results related to php (not something in my wheelhouse), but I went looking in the laravel.log file and found the log content I have included. The last line seems to say that the error is occurring at line 163 in app/Uploads/AttachmentService.php.

I can successfully create and delete attachments via the API, it is only when I try to update an attachment with a PUT request that I encounter this error. An example of my attempted curl requests is as follows:

curl -X PUT -H 'Authorization: Token MY_API_KEY' -F "name=TEST ATTACHMENT" -F "uploaded_to=2638" -F "file=@/path/to/file.txt" localhost:6875/api/attachments/100

I have tried various combinations of data (e.g. trying to only update the attachment name via application/json, trying to only update the file content via multipart form) and I get the same error message in all cases. I admit, I don't have a ton of experience with this sort of thing so it's entirely possible there's a simple issue that I'm missing. I can ultimately achieve my end goal by deleting the attachment and just uploading a new one in its place; however, it would be nice to not have to also update the attachment links each time I replace an attachment. Any help would be much appreciated!

Exact BookStack Version

v23.06.2

Log Content

#0 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(270): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /app/www/app/Uploads/AttachmentService.php(163): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()
#2 /app/www/app/Uploads/Controllers/AttachmentApiController.php(148): BookStack\Uploads\AttachmentService->updateFile()
#3 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): BookStack\Uploads\Controllers\AttachmentApiController->update()
#4 /app/www/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction()
#5 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(259): Illuminate\Routing\ControllerDispatcher->dispatch()
#6 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()
#7 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\Routing\Route->run()
#8 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#9 /app/www/app/Http/Middleware/CheckEmailConfirmed.php(47): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#10 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\Http\Middleware\CheckEmailConfirmed->handle()
#11 /app/www/app/Http/Middleware/PreventAuthenticatedResponseCaching.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#12 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\Http\Middleware\PreventAuthenticatedResponseCaching->handle()
#13 /app/www/app/Http/Middleware/ApiAuthenticate.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#14 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\Http\Middleware\ApiAuthenticate->handle()
#15 /app/www/app/Http/Middleware/StartSessionIfCookieExists.php(20): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#16 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\Http\Middleware\StartSessionIfCookieExists->handle()
#17 /app/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#18 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#19 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(126): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#20 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(57): Illuminate\Routing\Middleware\ThrottleRequests->handleRequest()
#21 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\ThrottleRequests->handle()
#22 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#23 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(797): Illuminate\Pipeline\Pipeline->then()
#24 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(776): Illuminate\Routing\Router->runRouteWithinStack()
#25 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(740): Illuminate\Routing\Router->runRoute()
#26 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(729): Illuminate\Routing\Router->dispatchToRoute()
#27 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(190): Illuminate\Routing\Router->dispatch()
#28 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#29 /app/www/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#30 /app/www/app/Http/Middleware/TrustProxies.php(41): Illuminate\Http\Middleware\TrustProxies->handle()
#31 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\Http\Middleware\TrustProxies->handle()
#32 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#33 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#34 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
#35 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#36 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#37 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#38 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#39 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#40 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Pipeline\Pipeline->then()
#41 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#42 /app/www/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#43 {main}
"}
[2023-10-19 21:44:30] production.ERROR: Undefined array key "name" {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined array key "name" at /app/www/app/Uploads/AttachmentService.php:163)
[stacktrace]

Hosting Environment

Hosted running in a Docker container using the lscr.io/linuxserver/bookstack image and the lscr.io/linuxserver/mariadb image

Originally created by @MQuillian on GitHub (Oct 20, 2023). ### Attempted Debugging - [X] I have read the debugging page ### Searched GitHub Issues - [X] I have searched GitHub for the issue. ### Describe the Scenario When attempting to update an attachment using the API, the update fails with the following response message: ` {"error":{"message":"Undefined array key \"name\"","code":500}}` My initial searching returned results related to php (not something in my wheelhouse), but I went looking in the `laravel.log` file and found the log content I have included. The last line seems to say that the error is occurring at line 163 in app/Uploads/AttachmentService.php. I can successfully create and delete attachments via the API, it is only when I try to update an attachment with a PUT request that I encounter this error. An example of my attempted curl requests is as follows: `curl -X PUT -H 'Authorization: Token MY_API_KEY' -F "name=TEST ATTACHMENT" -F "uploaded_to=2638" -F "file=@/path/to/file.txt" localhost:6875/api/attachments/100` I have tried various combinations of data (e.g. trying to only update the attachment name via application/json, trying to only update the file content via multipart form) and I get the same error message in all cases. I admit, I don't have a ton of experience with this sort of thing so it's entirely possible there's a simple issue that I'm missing. I can ultimately achieve my end goal by deleting the attachment and just uploading a new one in its place; however, it would be nice to not have to also update the attachment links each time I replace an attachment. Any help would be much appreciated! ### Exact BookStack Version v23.06.2 ### Log Content #0 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(270): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError() #1 /app/www/app/Uploads/AttachmentService.php(163): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}() #2 /app/www/app/Uploads/Controllers/AttachmentApiController.php(148): BookStack\\Uploads\\AttachmentService->updateFile() #3 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): BookStack\\Uploads\\Controllers\\AttachmentApiController->update() #4 /app/www/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\\Routing\\Controller->callAction() #5 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(259): Illuminate\\Routing\\ControllerDispatcher->dispatch() #6 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\\Routing\\Route->runController() #7 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\\Routing\\Route->run() #8 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}() #9 /app/www/app/Http/Middleware/CheckEmailConfirmed.php(47): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #10 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\\Http\\Middleware\\CheckEmailConfirmed->handle() #11 /app/www/app/Http/Middleware/PreventAuthenticatedResponseCaching.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #12 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\\Http\\Middleware\\PreventAuthenticatedResponseCaching->handle() #13 /app/www/app/Http/Middleware/ApiAuthenticate.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #14 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\\Http\\Middleware\\ApiAuthenticate->handle() #15 /app/www/app/Http/Middleware/StartSessionIfCookieExists.php(20): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #16 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\\Http\\Middleware\\StartSessionIfCookieExists->handle() #17 /app/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #18 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle() #19 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(126): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #20 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(57): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequest() #21 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle() #22 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #23 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(797): Illuminate\\Pipeline\\Pipeline->then() #24 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(776): Illuminate\\Routing\\Router->runRouteWithinStack() #25 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(740): Illuminate\\Routing\\Router->runRoute() #26 /app/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(729): Illuminate\\Routing\\Router->dispatchToRoute() #27 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(190): Illuminate\\Routing\\Router->dispatch() #28 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}() #29 /app/www/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #30 /app/www/app/Http/Middleware/TrustProxies.php(41): Illuminate\\Http\\Middleware\\TrustProxies->handle() #31 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): BookStack\\Http\\Middleware\\TrustProxies->handle() #32 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #33 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle() #34 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle() #35 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #36 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle() #37 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #38 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle() #39 /app/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}() #40 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\\Pipeline\\Pipeline->then() #41 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter() #42 /app/www/public/index.php(52): Illuminate\\Foundation\\Http\\Kernel->handle() #43 {main} "} [2023-10-19 21:44:30] production.ERROR: Undefined array key "name" {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined array key \"name\" at /app/www/app/Uploads/AttachmentService.php:163) [stacktrace] ### Hosting Environment Hosted running in a Docker container using the lscr.io/linuxserver/bookstack image and the lscr.io/linuxserver/mariadb image
OVERLORD added the 🐕 Support label 2026-02-05 08:23:58 +03:00
Author
Owner

@MQuillian commented on GitHub (Oct 20, 2023):

I felt like I was missing something I couldn't quite remember that was relevant... From the API documentation:

Form requests currently only work for POST requests due to how PHP handles request data. If you need to use these formats for PUT or DELETE requests you can work around this limitation by using a POST request and providing a "_method" parameter with the value equal to PUT or DELETE.

🤦‍♂️

@MQuillian commented on GitHub (Oct 20, 2023): I felt like I was missing something I couldn't quite remember that was relevant... From the API documentation: Form requests currently only work for POST requests due to how PHP handles request data. If you need to use these formats for PUT or DELETE requests you can work around this limitation by using a POST request and providing a "_method" parameter with the value equal to PUT or DELETE. 🤦‍♂️
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#4274