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

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

Loading…
Cancel
Save