mirror of
https://github.com/grocy/grocy.git
synced 2025-08-17 19:16:37 +00:00
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:
@@ -196,3 +196,9 @@ function QrCodeImgHtml(text)
|
||||
|
||||
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');
|
||||
}
|
||||
|
@@ -44,9 +44,9 @@ Grocy.Components.UserfieldsForm.Save = function(success, error)
|
||||
if (input[0].files.length > 0)
|
||||
{
|
||||
// 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,
|
||||
function(result)
|
||||
{
|
||||
|
@@ -13,7 +13,7 @@
|
||||
if ($("#instruction-manual")[0].files.length > 0)
|
||||
{
|
||||
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)
|
||||
|
@@ -96,7 +96,7 @@ $('.save-product-button').on('click', function(e)
|
||||
if ($("#product-picture")[0].files.length > 0)
|
||||
{
|
||||
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/';
|
||||
|
@@ -36,7 +36,7 @@ $('.save-recipe').on('click', function(e)
|
||||
if ($("#recipe-picture")[0].files.length > 0)
|
||||
{
|
||||
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/';
|
||||
|
@@ -39,7 +39,7 @@ $('#save-user-button').on('click', function(e)
|
||||
if ($("#user-picture")[0].files.length > 0)
|
||||
{
|
||||
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')
|
||||
|
Reference in New Issue
Block a user