Skip to content
Snippets Groups Projects
Unverified Commit 7d047b20 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3214675 by el7cosmos, bbrala, hehongbo, larowlan, alexpott: JSON:API...

Issue #3214675 by el7cosmos, bbrala, hehongbo, larowlan, alexpott: JSON:API Cannot upload files to public file root (Gets 422 Unprocessable Entity)

(cherry picked from commit a8d3f780)
parent fbb8e860
No related branches found
No related tags found
5 merge requests!10011Issue #3200534 by quietone, longwave, Kristen Pol: Use dataprovider for...,!2571Issue #3000717: Missing mapping for "nodereference_url" widget,!2521Issue #3185775: Place Views preview on the side on large monitors,!1479Issue #3250298: Return empty string "" with JSON Serializer instead of FALSE,!1478Issue #3250298: Return empty string "" with JSON Serializer instead of FALSE
......@@ -159,7 +159,8 @@ public function __construct(LoggerInterface $logger, FileSystemInterface $file_s
*/
public function handleFileUploadForField(FieldDefinitionInterface $field_definition, $filename, AccountInterface $owner) {
assert(is_a($field_definition->getClass(), FileFieldItemList::class, TRUE));
$destination = $this->getUploadLocation($field_definition->getSettings());
$settings = $field_definition->getSettings();
$destination = $this->getUploadLocation($settings);
// Check the destination file path is writable.
if (!$this->fileSystem->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY)) {
......@@ -172,6 +173,9 @@ public function handleFileUploadForField(FieldDefinitionInterface $field_definit
// Create the file.
$file_uri = "{$destination}/{$prepared_filename}";
if ($destination === $settings['uri_scheme'] . '://') {
$file_uri = "{$destination}{$prepared_filename}";
}
$temp_file_path = $this->streamUploadData();
......
......@@ -747,6 +747,27 @@ public function testFileUploadNoExtensionSetting() {
$this->assertFileExists('public://foobar/example.txt');
}
/**
* Tests using the file upload POST route no directory configured.
*/
public function testFileUploadNoDirectorySetting() {
$this->setUpAuthorization('POST');
$this->config('jsonapi.settings')->set('read_only', FALSE)->save(TRUE);
$uri = Url::fromUri('base:' . static::$postUri);
$this->field->setSetting('file_directory', '')
->save();
$response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'filename="example.txt"']);
$expected = $this->getExpectedDocument(1, 'example.txt', TRUE);
$expected['data']['attributes']['uri']['value'] = 'public://example.txt';
$expected['data']['attributes']['uri']['url'] = base_path() . $this->siteDirectory . '/files/example.txt';
$this->assertResponseData($expected, $response);
$this->assertFileExists('public://example.txt');
}
/**
* {@inheritdoc}
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment