Workaround for file upload problem when the file name contains Umlaute (seems to be a Linux only issue, fixes #1382)

This commit is contained in:
Bernd Bestel
2021-07-09 21:23:04 +02:00
parent 338a5016cf
commit 8348438148
6 changed files with 12 additions and 6 deletions

View File

@@ -196,3 +196,9 @@ function QrCodeImgHtml(text)
return img.outerHTML; return img.outerHTML;
} }
function CleanFileName(fileName)
{
// Umlaute seem to cause problems on Linux...
return fileName.toLowerCase().replaceAll(/ä/g, 'ae').replaceAll(/ö/g, 'oe').replaceAll(/ü/g, 'ue').replaceAll(/ß/g, 'ss');
}

View File

@@ -44,9 +44,9 @@ Grocy.Components.UserfieldsForm.Save = function(success, error)
if (input[0].files.length > 0) if (input[0].files.length > 0)
{ {
// Files service requires an extension // Files service requires an extension
var fileName = RandomString() + '.' + input[0].files[0].name.split('.').reverse()[0]; var fileName = RandomString() + '.' + CleanFileName(input[0].files[0].name.split('.').reverse()[0]);
jsonData[fieldName] = btoa(fileName) + '_' + btoa(input[0].files[0].name); jsonData[fieldName] = btoa(fileName) + '_' + btoa(CleanFileName(input[0].files[0].name));
Grocy.Api.UploadFile(input[0].files[0], 'userfiles', fileName, Grocy.Api.UploadFile(input[0].files[0], 'userfiles', fileName,
function(result) function(result)
{ {

View File

@@ -13,7 +13,7 @@
if ($("#instruction-manual")[0].files.length > 0) if ($("#instruction-manual")[0].files.length > 0)
{ {
var someRandomStuff = RandomString(); var someRandomStuff = RandomString();
jsonData.instruction_manual_file_name = someRandomStuff + $("#instruction-manual")[0].files[0].name; jsonData.instruction_manual_file_name = someRandomStuff + CleanFileName($("#instruction-manual")[0].files[0].name);
} }
if (Grocy.DeleteInstructionManualOnSave) if (Grocy.DeleteInstructionManualOnSave)

View File

@@ -96,7 +96,7 @@ $('.save-product-button').on('click', function(e)
if ($("#product-picture")[0].files.length > 0) if ($("#product-picture")[0].files.length > 0)
{ {
var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100); var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
jsonData.picture_file_name = someRandomStuff + $("#product-picture")[0].files[0].name; jsonData.picture_file_name = someRandomStuff + CleanFileName($("#product-picture")[0].files[0].name);
} }
const location = $(e.currentTarget).attr('data-location') == 'return' ? '/products?product=' : '/product/'; const location = $(e.currentTarget).attr('data-location') == 'return' ? '/products?product=' : '/product/';

View File

@@ -36,7 +36,7 @@ $('.save-recipe').on('click', function(e)
if ($("#recipe-picture")[0].files.length > 0) if ($("#recipe-picture")[0].files.length > 0)
{ {
var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100); var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
jsonData.picture_file_name = someRandomStuff + $("#recipe-picture")[0].files[0].name; jsonData.picture_file_name = someRandomStuff + CleanFileName($("#recipe-picture")[0].files[0].name);
} }
const location = $(e.currentTarget).attr('data-location') == 'return' ? '/recipes?recipe=' : '/recipe/'; const location = $(e.currentTarget).attr('data-location') == 'return' ? '/recipes?recipe=' : '/recipe/';

View File

@@ -39,7 +39,7 @@ $('#save-user-button').on('click', function(e)
if ($("#user-picture")[0].files.length > 0) if ($("#user-picture")[0].files.length > 0)
{ {
var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100); var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
jsonData.picture_file_name = someRandomStuff + $("#user-picture")[0].files[0].name; jsonData.picture_file_name = someRandomStuff + CleanFileName($("#user-picture")[0].files[0].name);
} }
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')