fixes filename encoding

This commit is contained in:
user 2025-02-25 16:04:06 +03:00
parent c6f30c6f76
commit 0cd755fe8d
2 changed files with 6 additions and 2 deletions

View File

@ -7,6 +7,7 @@ from mimetypes import guess_type
import aiofiles import aiofiles
from base58 import b58encode from base58 import b58encode
from base64 import b64decode
from sanic import response from sanic import response
from app.core.logger import make_log from app.core.logger import make_log
@ -34,6 +35,7 @@ async def s_api_v1_5_storage_post(request):
return response.json({"error": "Invalid X-Content-SHA256 header format"}, status=400) return response.json({"error": "Invalid X-Content-SHA256 header format"}, status=400)
provided_filename = request.headers.get("X-File-Name") provided_filename = request.headers.get("X-File-Name")
provided_filename = b64decode(provided_filename).decode("utf-8")
# Check if the file already exists in the database # Check if the file already exists in the database
db_session = request.ctx.db_session db_session = request.ctx.db_session

View File

@ -107,17 +107,19 @@
const hashHex = await computeSHA256(file); const hashHex = await computeSHA256(file);
appendLog(`Computed SHA-256 hash: ${hashHex}`); appendLog(`Computed SHA-256 hash: ${hashHex}`);
// Prepare the POST request with file as body and header X-Content-SHA256 // Prepare the POST request with file as body and additional header for filename
const encodedFileName = btoa(unescape(encodeURIComponent(file.name)));
const response = await fetch(BASE_URL, { const response = await fetch(BASE_URL, {
method: "POST", method: "POST",
headers: { headers: {
"X-Content-SHA256": hashHex, "X-Content-SHA256": hashHex,
"X-File-Name": file.name, // NEW: передаём имя файла "X-File-Name": encodedFileName, // NEW: передаём имя файла в base64
"Content-Type": file.type || "application/octet-stream" "Content-Type": file.type || "application/octet-stream"
}, },
body: file body: file
}); });
if (!response.ok) { if (!response.ok) {
const errorData = await response.json(); const errorData = await response.json();
uploadResult.textContent = `Ошибка: ${errorData.error}`; uploadResult.textContent = `Ошибка: ${errorData.error}`;