Fixed an encoding problem when uploading scenarios to the ASL Scenario Archive.

master
Pacman Ghost 3 years ago
parent 284a8e7042
commit 95b7c52be4
  1. 6
      vasl_templates/webapp/static/scenario-upload.js
  2. 12
      vasl_templates/webapp/static/utils.js

@ -139,7 +139,7 @@ window.uploadScenario = function() {
) ;
}
// shpw the upload dialog
// show the upload dialog
$( "#scenario-upload-dialog" ).dialog( {
title: "Upload to the ASL Scenario Archive",
dialogClass: "scenario-upload",
@ -274,8 +274,10 @@ function uploadFiles( asaScenarioId )
// prepare the upload
var formData = new FormData() ;
var vtSetupJson = JSON.stringify( vtSetup, null, 4 ) ;
var vtSetupJsonUTF8 = (new TextEncoder()).encode( vtSetupJson ) ;
formData.append( "vt_setup",
makeBlob( JSON.stringify( vtSetup, null, 4 ), "application/json" ),
makeBlob( vtSetupJsonUTF8, "application/json" ),
prefix + "|" + "scenario.json"
) ;
if ( gVsavData ) {

@ -608,9 +608,15 @@ function stopEvent( evt )
function makeBlob( data, mimeType )
{
// create a Blob from a binary string
var bytes = new Uint8Array( data.length ) ;
for ( var i=0 ; i < data.length ; ++i )
bytes[i] = data.charCodeAt( i ) ;
var bytes ;
if ( typeof data === "object" )
bytes = data ; // i.e. output from TextEncoder.encode()
else if ( typeof data === "string" ) {
bytes = new Uint8Array( data.length ) ;
for ( var i=0 ; i < data.length ; ++i )
bytes[i] = data.charCodeAt( i ) ;
} else
return null ;
return new Blob( [bytes], {
type: mimeType || "application/octet-stream"
} ) ;

Loading…
Cancel
Save