# Work with Files In-Game

### Retrieving Player Files

#### Retrieve All Player Files

Retrieve all files associated with the player.

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.GetAllPlayerFiles((response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully retrieved player files: " + response.items.Length);
    } 
    else
    {
        Debug.Log("Error retrieving player storage");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-01b6c236bbb893539f3d26238576583e8e9e29ad%2FRetrieve%20All%20Player%20Files?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/jr6b9s4s/">Blueprint Example of retrieving all player files</a></p></figcaption></figure>
{% endtab %}

{% tab title="REST" %}

```bash
curl -X GET "https://api.lootlocker.io/game/player/files" \
  -H "x-session-token: your_token_here" \
  -H "LL-Version: 2021-03-01"
```

Example response:

```json
{
  "items": [
    {
      "id": 318,
      "revision_id": "01GPNZHCVEF6F0QGA3V2B7CN44",
      "name": "smol.jpg",
      "size": 7056,
      "purpose": "SAVE_GAME",
      "public": false,
      "url": "https://cdn.lootlocker.io/2/892/oJnNPGsiuzytMOJPatwtPilfsfykSBGp.jpg?Expires=1635369933&Signature=Wp-PUZdoh3XdqQNOnPP80-q81ftGpLVJ3oub3RajnfjaP15rHzVWCCJ8e8lzpzrzdilu1gxoTiK1NT7iZayJXV~1XvcagCbkLCsrLkHlDZ0ms17C1YL5iNu1crBCJOhOhpwhknDmgt95NWa2GjLydylj7-0mqjALoURAMzpWvmbXUClUhtzIgGsBIEn2jy~syplWtMstTHE13EHmsxqfbAr8fkp91JGHaLFqSJL5YvlnIe5WoVNeBII8tjBb6YtEEF2dyliLyJOk8RaGtCDodKMmwOlwAlw-~lyfPrUOxH62c87-vkn8~uPQgAxcX0kp6NDudFrO5uiyESyOymIscw__&Key-Pair-Id=APKAIIBA3IODTCVA4BKQ",
      "url_expires_at": "2021-10-27T21:25:33.339117882Z",
      "created_at": "2021-10-27T14:20:31Z"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

#### Retrieve All Public Files From Another Player

Retrieve all (public) files associated with another player.

{% tabs %}
{% tab title="Unity" %}

```csharp
int playerId = 1;

LootLockerSDKManager.GetAllPlayerFiles(playerId, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully retrieved player files: " + response.items.Length);
    } 
    else
    {
        Debug.Log("Error retrieving player storage");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-958a48c51d7557b737c6de8273b3ba3fe6ed8084%2FGet%20Other%20Players%20File?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/k3hhzja1/">Blueprint example of retrieving all files from another player marked public</a></p></figcaption></figure>
{% endtab %}

{% tab title="REST" %}

```bash
curl -X GET "https://api.lootlocker.io/game/player/{player_id}/files" \
  -H "x-session-token: your_token_here" \
  -H "LL-Version: 2021-03-01"
```

Example response:

```json
{
  "items": [
    {
      "id": 5318,
      "revision_id": "01GPNZHCVEF6F0QGA3V2B7CN44",
      "name": "world.jpg",
      "size": 7056,
      "purpose": "WORLD",
      "public": true,
      "url": "https://cdn.lootlocker.io/2/892/oJnNPGsiuzytMOJPatwtPilfsfykSBGp.jpg?Expires=1635369933&Signature=Wp-PUZdoh3XdqQNOnPP80-q81ftGpLVJ3oub3RajnfjaP15rHzVWCCJ8e8lzpzrzdilu1gxoTiK1NT7iZayJXV~1XvcagCbkLCsrLkHlDZ0ms17C1YL5iNu1crBCJOhOhpwhknDmgt95NWa2GjLydylj7-0mqjALoURAMzpWvmbXUClUhtzIgGsBIEn2jy~syplWtMstTHE13EHmsxqfbAr8fkp91JGHaLFqSJL5YvlnIe5WoVNeBII8tjBb6YtEEF2dyliLyJOk8RaGtCDodKMmwOlwAlw-~lyfPrUOxH62c87-vkn8~uPQgAxcX0kp6NDudFrO5uiyESyOymIscw__&Key-Pair-Id=APKAIIBA3IODTCVA4BKQ",
      "url_expires_at": "2022-06-27T21:25:33.339117882Z",
      "created_at": "2022-06-27T14:20:31Z"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

#### Retrieve Single Player File

Retrieve a specific player file.

{% tabs %}
{% tab title="Unity" %}

```csharp
int playerFileId = 1;
LootLockerSDKManager.GetPlayerFile(playerFileId, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully retrieved player file with id: " + response.id);
        
    } 
    else
    {
        Debug.Log("Error retrieving player file");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-b81f1d78a4a0ba87c92ee2ceda50cd5d153cd2b5%2FGet%20Single%20Player%20File?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/enoyu93i/">Blueprint example for retrieving a specific player file</a></p></figcaption></figure>
{% endtab %}

{% tab title="REST" %}

```bash
curl -X GET "https://api.lootlocker.io/game/player/files/{file_id}" \
  -H "x-session-token: your_token_here" \
  -H "LL-Version: 2021-03-01"
```

example response:

```json
{
  "id": 318,
  "revision_id": "01GPNZHCVEF6F0QGA3V2B7CN44",
  "name": "smol.jpg",
  "size": 7056,
  "purpose": "SAVE_GAME",
  "public": false,
  "url": "https://cdn.lootlocker.io/2/892/oJnNPGsiuzytMOJPatwtPilfsfykSBGp.jpg?Expires=1635370000&Signature=JKJTvRoZpxgtebwCqtuADp-mH4j958vxo29LvRtWv~VC4iSfQHw5S8YFMVPMiWSJ3s-RY2V5VWBt1njWAjq~4fzDwSVXp6h0a5rPmG0oYa6~BId~sz8Blab2PCPkUMeYkLRG5EsnQyDHwPdHgIVAgZb5fwyVuKldmyQnbqeeHj9DmyoP8AmUsH6OJ63GQw2GkjRhw0x9B3jfn079LdqH0fVX80-UIfv7FRT-gt9fINsBT3ujy5~GoP91mJwPh6EV9xbQmZvAI4j0~5adP4mD01zYum3SARXqPdtax9MWiC42Ad-ADQQje3hsuimaDlhIgELfFhRG1il3FEcNCdw4aA__&Key-Pair-Id=APKAIIBA3IODTCVA4BKQ",
  "url_expires_at": "2021-10-27T21:26:40.407880449Z",
  "created_at": "2021-10-27T14:20:31Z"
}
```

{% endtab %}
{% endtabs %}

### Uploading Player Files

#### Upload a Private Player File From Path

Upload a (private) player file from the file's path.

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.UploadPlayerFile("/path/to/file/save_game.zip", "save_game", response =>
{
    if (response.success)
    {
        Debug.Log("Successfully uploaded player file, url: " + response.url);
    } 
    else
    {
        Debug.Log("Error uploading player file");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-8d23db1d84a3a22f463ee415201a069195da007e%2FUpload%20Player%20File?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/-sx-s5by/">Blueprint example of uploading a player file</a></p></figcaption></figure>

{% hint style="warning" %}
The Boolean "Is Public" should be set to false in this case, to upload a private file!
{% endhint %}
{% endtab %}

{% tab title="REST" %}

```bash
curl -X POST "https://api.lootlocker.io/game/player/files" \
  -H "x-session-token: your_token_here" \
  -H "LL-Version: 2021-03-01" \
  -F 'file=@"path/to/your/file"' \
  -F 'purpose="save_game"' \
  -F 'is_public="false"'
```

Example response:

```json
{
  "id": 318,
  "revision_id": "01GPNZHCVEF6F0QGA3V2B7CN44",
  "name": "save_game_1.zip",
  "size": 7056,
  "purpose": "SAVE_GAME_SLOT_1",
  "public": false,
  "url": "https://cdn.lootlocker.io/2/892/oJnNPGsiuzytMOJPatwtPilfsfykSBGp.jpg?Expires=1635366031&Signature=Z7MG~WgUyqpBNlXRePXxuV2uFbI0fEkAa3chk-3YO2XlWyd1veSl5V2dmFyVM1CndY6cfHo9ds3ilthwY~NjUiFmrx6ycfG3GJ5Z~kqzuyyMpH~LXTh~tIwnZpJpKScFUeBz5PpkSQPfOo4nuWktQBmpIgOhLlD2cWKOlQllBaIhjFvUh1HGIs-1u2-DiX9eDIgBDYzP4k0aMGH0aKjKF8Wb1jbAwaAcvQBeiPC~B~DgjlsHy6UjS59nYLCI-3EMheivk7H5-z-R65Au8VGg1koP89QtEjViy2HKbMKId~tQ3-cJg-ylRGHbE7jGlRyFC9CQLfeJXqx-IgaKfjVZCQ__&Key-Pair-Id=APKAIIBA3IODTCVA4BKQ",
  "url_expires_at": "2021-10-27T20:20:31.433987069Z",
  "created_at": "2021-10-27T14:20:31.428496822Z"
}
```

{% endtab %}
{% endtabs %}

#### Upload a Public Player File From Path

Upload a (public) player file from the file's path.

{% tabs %}
{% tab title="Unity" %}

```csharp
// You can also set this to false, if omitted it defaults to false
bool isPublic = true;

LootLockerSDKManager.UploadPlayerFile("/path/to/file/save_game.zip", "save_game", isPublic, response =>
{
    if (response.success)
    {
        Debug.Log("Successfully uploaded player file, url: " + response.url);
    } 
    else
    {
        Debug.Log("Error uploading player file");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-8d23db1d84a3a22f463ee415201a069195da007e%2FUpload%20Player%20File?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/-sx-s5by/">Blueprint example of uploading a player file</a></p></figcaption></figure>

{% hint style="warning" %}
The Boolean "Is Public" should be set to true in this case, to upload a public file!
{% endhint %}
{% endtab %}
{% endtabs %}

#### Upload a Private Player File Using FileStream

Upload a (private) file using FileStream.

{% tabs %}
{% tab title="Unity" %}

```csharp
var file = File.Open("/path/to/file/save_game.zip"", FileMode.Open);
        
LootLockerSDKManager.UploadPlayerFile(file, "player_file", response =>
{
    if (response.success)
    {
        Debug.Log("Successfully uploaded player file, url: " + response.url);
    } 
    else
    {
        Debug.Log("Error uploading player file");
    }
});
```

{% endtab %}
{% endtabs %}

#### Upload a Public Player File Using FileStream

Upload a (public) file using FileStream.

{% tabs %}
{% tab title="Unity" %}

```csharp
var file = File.Open("/path/to/file/save_game.zip"", FileMode.Open);

// You can also set this to false, if omitted it defaults to false
bool isPublic = true;

LootLockerSDKManager.UploadPlayerFile(file, "player_file", isPublic, response =>
{
    if (response.success)
    {
        Debug.Log("Successfully uploaded player file, url: " + response.url);
    } 
    else
    {
        Debug.Log("Error uploading player file");
    }
});
```

{% endtab %}
{% endtabs %}

#### Upload a Private Player File Using Byte Array

Upload a (private) file using byte array.

{% tabs %}
{% tab title="Unity" %}

```csharp
var file = File.Open("/path/to/file/save_game.zip"", FileMode.Open);
var fileBytes = new byte[file.Length];
file.Read(fileBytes, 0, Convert.ToInt32(file.Length));

LootLockerSDKManager.UploadPlayerFile(fileBytes, "filename", "save_game", response =>
{
    if (response.success)
    {
        Debug.Log("Successfully uploaded player file, url: " + response.url);
    } 
    else
    {
        Debug.Log("Error uploading player file");
    }
});
```

{% endtab %}
{% endtabs %}

#### Upload a Public Player File Using Byte Array

Upload a (public) file using byte array.

{% tabs %}
{% tab title="Unity" %}

```csharp
var file = File.Open("/path/to/file/save_game.zip"", FileMode.Open);
var fileBytes = new byte[file.Length];
file.Read(fileBytes, 0, Convert.ToInt32(file.Length));

// You can also set this to false, if omitted it defaults to false
bool isPublic = true;

LootLockerSDKManager.UploadPlayerFile(fileBytes, "filename", "save_game", isPublic, response =>
{
    if (response.success)
    {
        Debug.Log("Successfully uploaded player file, url: " + response.url);
    } 
    else
    {
        Debug.Log("Error uploading player file");
    }
});
```

{% endtab %}
{% endtabs %}

### Updating Player Files

#### Update a Player File from Path

Update a player file from the file's path.

{% tabs %}
{% tab title="Unity" %}

```csharp
// The ID of the file can be retrieved when creating the file
// or when listing all player files.
int playerFileID = 0;
LootLockerSDKManager.UpdatePlayerFile(playerFileID, "/path/to/file/save_game.zip", response =>
{
    if (response.success)
    {
        Debug.Log("Successfully updated player file, url: " + response.url);
    } 
    else
    {
        Debug.Log("Error updating player file");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-bf0398534723effa66b8ce799b24dc546b03c3ce%2Fimage.png?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/cqxeq04h/">Blueprint example of updating a player file</a></p></figcaption></figure>

{% hint style="danger" %}
Be aware that if you update a file, make sure to include everything, even what you don't want to update, as you can update a file to contain nothing.
{% endhint %}
{% endtab %}

{% tab title="REST" %}

```bash
curl -X PUT 'https://api.lootlocker.io/game/player/files/:file_id' \
  -H "x-session-token: your_token_here" \
  -H "LL-Version: 2021-03-01"
  -F 'file=@"path/to/your/file"'
```

Example response:

```json
{
  "id": 318,
  "revision_id": "01GPNZHCVEF6F0QGA3V2B7CN44",
  "name": "save_game_1.zip",
  "size": 7056,
  "purpose": "SAVE_GAME",
  "public": false,
  "url": "https://cdn.lootlocker.io/2/892/oJnNPGsiuzytMOJPatwtPilfsfykSBGp.jpg?Expires=1635366031&Signature=Z7MG~WgUyqpBNlXRePXxuV2uFbI0fEkAa3chk-3YO2XlWyd1veSl5V2dmFyVM1CndY6cfHo9ds3ilthwY~NjUiFmrx6ycfG3GJ5Z~kqzuyyMpH~LXTh~tIwnZpJpKScFUeBz5PpkSQPfOo4nuWktQBmpIgOhLlD2cWKOlQllBaIhjFvUh1HGIs-1u2-DiX9eDIgBDYzP4k0aMGH0aKjKF8Wb1jbAwaAcvQBeiPC~B~DgjlsHy6UjS59nYLCI-3EMheivk7H5-z-R65Au8VGg1koP89QtEjViy2HKbMKId~tQ3-cJg-ylRGHbE7jGlRyFC9CQLfeJXqx-IgaKfjVZCQ__&Key-Pair-Id=APKAIIBA3IODTCVA4BKQ",
  "url_expires_at": "2021-10-27T20:20:31.433987069Z",
  "created_at": "2021-10-27T14:20:31.428496822Z"
}
```

{% endtab %}
{% endtabs %}

#### Update a Player File Using Byte Array

Update a player file using byte array.

{% tabs %}
{% tab title="Unity" %}

```csharp
// The ID of the file can be retrieved when creating the file
// or when listing all player files.
int playerFileID = 0;
var file = File.Open("/path/to/file/save_game.zip"", FileMode.Open);
var fileBytes = new byte[file.Length];
file.Read(fileBytes, 0, Convert.ToInt32(file.Length));
LootLockerSDKManager.UpdatePlayerFile(playerFileID, fileBytes, response =>
{
    if (response.success)
    {
        Debug.Log("Successfully updated player file, url: " + response.url);
    } 
    else
    {
        Debug.Log("Error updating player file");
    }
});
```

{% endtab %}
{% endtabs %}

#### Update a Player File Using FileStream

Update a player file using FileStream.

{% tabs %}
{% tab title="Unity" %}

```csharp
// The ID of the file can be retrieved when creating the file
// or when listing all player files.
int playerFileID = 0;
var file = File.Open("/path/to/file/save_game.zip"", FileMode.Open);
LootLockerSDKManager.UpdatePlayerFile(playerFileID, file, response =>
{
    if (response.success)
    {
        Debug.Log("Successfully updated player file, url: " + response.url);
    } 
    else
    {
        Debug.Log("Error updating player file");
    }
});
```

{% endtab %}
{% endtabs %}

### Deleting Player Files

#### Delete Player File

Delete a player file.

{% tabs %}
{% tab title="Unity" %}

```csharp
// The ID of the file can be retrieved when creating the file
// or when listing all player files.
int playerFileId = 1;

LootLockerSDKManager.DeletePlayerFile(playerFileId, response => 
{
    if (response.success)
    {
        Debug.Log("Successfully deleted player file with id: " + playerFileId);
    } 
    else
    {
        Debug.Log("Error deleting player file");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-df55b1219b670b84cc34be5e46050887ffa3d1e4%2FDelete%20Player%20File?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/t8zjut80/">Blueprint example of deleting a player file</a></p></figcaption></figure>
{% endtab %}

{% tab title="REST" %}

```bash
curl -X DELETE "https://api.lootlocker.io/game/player/files/{file_id}" \
  -H "x-session-token: your_token_here" \
  -H "LL-Version: 2021-03-01"
```

{% endtab %}
{% endtabs %}
