fixes filename encoding
This commit is contained in:
parent
c6f30c6f76
commit
0cd755fe8d
|
|
@ -7,6 +7,7 @@ from mimetypes import guess_type
|
|||
|
||||
import aiofiles
|
||||
from base58 import b58encode
|
||||
from base64 import b64decode
|
||||
from sanic import response
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
db_session = request.ctx.db_session
|
||||
|
|
|
|||
|
|
@ -107,16 +107,18 @@
|
|||
const hashHex = await computeSHA256(file);
|
||||
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, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-Content-SHA256": hashHex,
|
||||
"X-File-Name": file.name, // NEW: передаём имя файла
|
||||
"X-File-Name": encodedFileName, // NEW: передаём имя файла в base64
|
||||
"Content-Type": file.type || "application/octet-stream"
|
||||
},
|
||||
body: file
|
||||
});
|
||||
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
|
|
|
|||
Loading…
Reference in New Issue