Was able to figure this out..
First, I had an error in assigning the uploadURL from the response.
uploadURL = response.data.UploadDetails.UploadUrl;
should have been
uploadURL = response.data.UploadDetails[0].UploadUrl;
While using fetch should probably work as well, ended up getting it to work with XMLHttpRequest.
I got the following code to successfully push the data to playfab as a file.
In the example below I am putting DataTest in but in my use case I have a large array of tile map data that I am storing. In place of DataTest in my example I set my tile map data equal to a global variable and send that within the send instead.
General flow is that once the data is ready to send, call PF_InitiateFileUploads passing the entity information received from login which I had stored in a global variable in the event sheet. In the callback, send data to url received with XMLHttpRequest, initiate trigger to event sheet with status = "ready", then followup with with a call to FinalizeFileUploads.
//InitiateFileUploads
//https://api.playfab.com/documentation/Data/method/InitiateFileUploads
function PF_InitiateFileUploads(f_EntityId,f_EntityType,f_EntityTypeString){
var request = {
"FileNames": [
"mapData"
],
"Entity": {
"Id": f_EntityId,
"Type": f_EntityType,
"TypeString": f_EntityTypeString
}
}
PlayFabDataSDK.InitiateFileUploads(request,onInitiateFileUploadsResponse);
}
//FinalizeFileUploads
//https://api.playfab.com/documentation/Data/method/FinalizeFileUploads
function PF_FinalizeFileUploads(f_EntityId,f_EntityType,f_EntityTypeString){
var request = {
"FileNames": [
"mapData"
],
"Entity": {
"Id": f_EntityId,
"Type": f_EntityType,
"TypeString": f_EntityTypeString
}
}
PlayFabDataSDK.FinalizeFileUploads(request,onFinalizeFileUploadsResponse);
}
function onInitiateFileUploadsResponse(response, error) {
var uploadURL;
var DataTest={
posX: 45,
posY: 23
};
if (response !== null) {
console.log("InitiateFileUploads response received")
console.log("InitiateFileUploads response: " + JSON.stringify(response));
uploadURL = response.data.UploadDetails[0].UploadUrl;
console.log(uploadURL)
var xhr = new XMLHttpRequest();
xhr.open("PUT", uploadURL, true); // true : asynchrone false: synchrone
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify(DataTest));
xhr.onreadystatechange = function () {
if (this.readyState === 4) {
console.log(this.responseText)
var status = "ready";
console.log("status: " + status)
myIruntime.callFunction("ES_initiateFileUploads_Results",status)
}
};
} else if (error !== null) {
console.log("InitiateFileUploads error received")
console.log("InitiateFileUploads error: " + JSON.stringify(error));
}
}
function onFinalizeFileUploadsResponse(response, error) {
if (response !== null) {
console.log("FinalizeFileUploads response received")
console.log("FinalizeFileUploads response: " + JSON.stringify(response));
} else if (error !== null) {
console.log("FinalizeFileUploads error received")
console.log("FinalizeFileUploads error: " + JSON.stringify(error));
}
}