File upload fails if filename has special character (e.g. Lousã.js), depending on browser used
Try to upload (via drag and drop or the file requester) some non-empty file with a name such as Lousã.js. It will immediately show up as having been uploaded with 0 size.
This issue seems similar to #269 , but it occurs in my installation of v2.1.0, where that issue should be fixed.
This occurs with the host running on an LXC on Proxmox, client on a Vivaldi 7.5.3735.58 (Stable channel) stable (64-bit) on Linux. Uploading was successful with the file renamed to Lousa.js.
Trying the same on Brave on Linux, it crashes the browser when using the special character.
On Firefox on Linux, it does upload correctly with the special character in the file name.
Thanks for the report. I assume you have cleared the cache or used incognito mode? The only thing I could image why this is happening, is that the JS portion does not do the base64 correctly (as it normally doesn't operate with utf-8)...
Also are there any error messages in the browser console?
Firefox and Brave tested with first time access to Gokapi, seems unlikely anything was present in the cache. Tried Brave again in incognito, but as it crashes, I can't see if anything gets logged to the console.
Vivaldi tried incognito as well as non-incognito. Vivaldi doesn't give any messages in the console when I drag-and-drop the file with special character to the upload area, it just "uploads" with 0 size. Console is set to show all levels of messages. It does show a message upon loading Gokapi, but that's before attempting to upload:
inject-root-bundle.js:1 RSS_Basic_Detect.js: Expected contentType string Jn @ inject-root-bundle.js:1 Promise.then Yn @ inject-root-bundle.js:1 (anonymous) @ inject-root-bundle.js:1 (anonymous) @ inject-root-bundle.js:1 (anonymous) @ inject-root-bundle.js:1
The inject.js error you are getting is most likely from an adblocker or something similar.
I tried it with a Vivaldi 7.5.3735.66-1 on Ubuntu 24.04 amd64 and was unfortunately unable to reproduce the problem...
If you paste the following code into the browser console and upload a new file without reloading the page, does it then work?
function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
async function apiChunkComplete(uuid, filename, filesize, realsize, contenttype, allowedDownloads, expiryDays, password, isE2E, nonblocking) {
const apiUrl = './api/chunk/complete';
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apikey': systemKey,
'uuid': uuid,
'filename': 'base64:' + b64EncodeUnicode(filename),
'filesize': filesize,
'realsize': realsize,
'contenttype': contenttype,
'allowedDownloads': allowedDownloads,
'expiryDays': expiryDays,
'password': password,
'isE2E': isE2E,
'nonblocking': nonblocking
},
};
try {
const response = await fetch(apiUrl, requestOptions);
if (!response.ok) {
let errorMessage;
// Attempt to parse JSON, fallback to text if parsing fails
try {
const errorResponse = await response.json();
errorMessage = errorResponse.ErrorMessage || `Request failed with status: ${response.status}`;
} catch {
// Handle non-JSON error
const errorText = await response.text();
errorMessage = errorText || `Request failed with status: ${response.status}`;
}
throw new Error(errorMessage);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error in apiChunkComplete:", error);
throw error;
}
}
Thanks. I'm currently away from my computer for a number of weeks, so I'm unable to test. FWIW I'm on a KDE Manjaro, Ubuntu is typically Gnome. I've now also tried Chrome and Firefox on Android and those work correctly.
I'll look into it when I have access again, if you prefer to close the issue until then I can reopen or file a new one when I'm back.
I'll just leave it open for now, let me know once you've tried it :)
Great, will do, thanks
@anxix did the fix work for you?
Can't tell yet, I'm away from my laptop for weeks I'm afraid.
Hi, I've tested after I paste in the code and it doesn't work. Vivaldi browser is updated to 7.6.3797.63, Gokapi still at 2.1.0. The console doesn't show any additional messages.