---
title: File
url: amazon-pay-api-v2/file.html
---

* TOC
{:toc}
{::options toc_levels="3" /}

***

## Overview

Upload and manage files for dispute evidence and other documentation needs. The API supports common file formats and provides secure upload URLs.

<script>
  function keySpecifics(){
    const keyQuery = "?environmentSpecificKeys=";
    const currentSetting = window.location.search?.split("?environmentSpecificKeys=")[1] ?? 'false';
    const newSetting = currentSetting === 'false' ? 'true' : 'false';
    window.location = window.location.origin + window.location.pathname + keyQuery + newSetting // +  window.location.hash (not included as it feels weird to jump down)
  }
</script>
<div style="display:none" class="environmentSpecificKeys">
  <div markdown="span" class="alert alert-info" role="alert"><i class="fa fa-info-circle"></i> <b>Note:</b> If your publicKeyId <b>_does not_</b> have an environment prefix (does not begin with 'SANDBOX' or 'LIVE') follow <a href='#' onclick='keySpecifics()' rel='noopener noreferrer'>these instructions</a> instead.</div>
</div>
<div style="display:none" class="notEnvironmentSpecificKeys">
  <div markdown="span" class="alert alert-info" role="alert"><i class="fa fa-info-circle"></i> <b>Note:</b> If your publicKeyId has an environment prefix (for example: SANDBOX-AFVX7ULWSGBZ5535PCUQOY7B) follow <a href='#' onclick='keySpecifics()' rel='noopener noreferrer'>these instructions</a> instead.</div>
</div>


Supported operations:

<div style="display:none" class="environmentSpecificKeys">
<ul id="profileTabs" class="nav nav-tabs">
  <li class="nav-item"><a class="active nav-link noExtIcon" href="#ustab" data-toggle="tab">US</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#eutab" data-toggle="tab">EU / UK</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#jptab" data-toggle="tab">JP</a></li>
</ul>
<div class="tab-content">
  <div role="tabpanel" class="tab-pane active" id="ustab" markdown="block">   
<div markdown="block">
* **Upload File** - POST https://pay-api.amazon.com/:version/files
</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="eutab" markdown="block">
<div markdown="block">
* **Upload File** - POST https://pay-api.amazon.eu/:version/files
</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="jptab" markdown="block">
<div markdown="block">
* **Upload File** - POST https://pay-api.amazon.jp/:version/files
</div>
  </div>
</div>
</div>
<div style="display:none" class="notEnvironmentSpecificKeys">
<ul id="profileTabs" class="nav nav-tabs">
  <li class="nav-item"><a class="active nav-link noExtIcon" href="#ustabNESK" data-toggle="tab">US</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#eutabNESK" data-toggle="tab">EU / UK</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#jptabNESK" data-toggle="tab">JP</a></li>
</ul>
<div class="tab-content">
  <div role="tabpanel" class="tab-pane active" id="ustabNESK" markdown="block">   
<div markdown="block">
* **Upload File** - POST https://pay-api.amazon.com/:environment/:version/files
</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="eutabNESK" markdown="block">
<div markdown="block">
* **Upload File** - POST https://pay-api.amazon.eu/:environment/:version/files
</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="jptabNESK" markdown="block">
<div markdown="block">
* **Upload File** - POST https://pay-api.amazon.jp/:environment/:version/files
</div>
  </div>
</div>
</div>

### File Object

<table width="100%" border="1">
    <tbody>
        <tr id='PDP9CANnxUg'>
            <td id='s:PDP9CANnxUg;PDP9CAuq5ca' style='vertical-align: top; font-weight: bold; width: 30%;' class='bold'>Property
                <br /></td>
            <td id='s:PDP9CANnxUg;PDP9CA8E4CV' style='vertical-align: top; font-weight: bold; width: 70%;' class='bold'>Description
                <br /></td>
        </tr>
        <tr id='PDP9CA4XqGQ'>
            <td id='s:PDP9CA4XqGQ;PDP9CAuq5ca' style='vertical-align: top;'>id<br><br>Type: string
                <br /></td>
            <td id='s:PDP9CA4XqGQ;PDP9CA8E4CV' style='vertical-align: top;'>Unique identifier for referencing the file<br><br><br>
                <br /></td>
        </tr>
        <tr id=''>
            <td id='PDP9CAEkyVK' style='vertical-align: top;'>type<br /><br />Type: <a href="#supported-file-types">filetype [Enum]</a>
                <br /></td>
            <td id='' style='vertical-align: top;'>File format (jpg, pdf, etc.)
                <br /></td>
        </tr>
        <tr id=''>
            <td id='PDP9CAEkyVK' style='vertical-align: top;'>purpose<br><br>Type: <a href="#filepurpose">filePurpose [Enum]</a>
                <br /></td>
            <td id='' style='vertical-align: top;'>Intended use (e.g., disputeEvidence)<br><br><br>
                <br /></td>
        </tr>
        <tr id='PDP9CAEkyVK'>
            <td id='' style='vertical-align: top;'>size<br /><br />Type: int
                <br /></td>
            <td id='' style='vertical-align: top;'>File size in bytes
                <br /></td>
        </tr>
        <tr id='PDP9CAOadtI'>
            <td id='s:PDP9CAOadtI;PDP9CAuq5ca' style='vertical-align: top;'>uploadTimestamp<br><br>Type: dateTime
                <br /></td>
            <td id='s:PDP9CAOadtI;PDP9CA8E4CV' style='vertical-align: top;'>Upload time in ISO 8601 format
                <br /></td>
        </tr>
        <tr id='PDP9CA0nAGy'>
            <td id='s:PDP9CA0nAGy;PDP9CAuq5ca' style='vertical-align: top;'>url<br><br>Type: String
                <br /></td>
            <td id='s:PDP9CA0nAGy;PDP9CA8E4CV' style='vertical-align: top;'>Download URL for the file
                <br /></td>
        </tr>
        <tr id='PDP9CAEkyVK'>
            <td id='s:PDP9CAEkyVK;PDP9CAuq5ca' style='vertical-align: top;'>urlExpirationTimestamp<br><br>Type: dateTime
                <br /></td>
            <td id='s:PDP9CAEkyVK;PDP9CA8E4CV' style='vertical-align: top;'>URL expiration time
                <br /></td>
        </tr>
    </tbody>
</table>

#### Enum

#### **filePurpose**
<table width="100%" border="1">
    <tbody>
        <tr id='PDP9CANnxUg'>
            <td id='s:PDP9CANnxUg;PDP9CAuq5ca' style='vertical-align: top; font-weight: bold; width: 30%;' class='bold'>Value
                <br /></td>
            <td id='s:PDP9CANnxUg;PDP9CA8E4CV' style='vertical-align: top; font-weight: bold; width: 70%;' class='bold'>Description
                <br /></td>
        </tr>
        <tr id='PDP9CA4XqGQ'>
            <td id='s:PDP9CA4XqGQ;PDP9CAuq5ca' style='vertical-align: top;'>disputeEvidence
                <br /></td>
            <td id='s:PDP9CA4XqGQ;PDP9CA8E4CV' style='vertical-align: top;'>The file provided will be used as a dispute evidence
                <br /></td>
        </tr>
    </tbody>
</table>

### Upload files

The API provides a two-step process to upload files securely.

#### Step 1: Get Upload URL

First, request a secure upload URL:

#### Request

<div style="display:none" class="environmentSpecificKeys">
<code style="color: black">
curl "https://pay-api.amazon.com/v2/files" \ <br />
-X POST \ <br />
-H "authorization: Bearer YOUR_TOKEN" \ <br />
-H "x-amz-pay-date: 20201012T235046Z" \ <br />
-H "x-amz-pay-idempotency-key: YOUR_IDEMPOTENCY_KEY" \ <br />
-d @request_body <br />
</code>
</div>
<div style="display:none" class="notEnvironmentSpecificKeys">
<code style="color: black">
curl "https://pay-api.amazon.com/:environment/v2/files" \ <br />
-X POST \ <br />
-H "authorization: Bearer YOUR_TOKEN" \ <br />
-H "x-amz-pay-date: 20201012T235046Z" \ <br />
-H "x-amz-pay-idempotency-key: YOUR_IDEMPOTENCY_KEY" \ <br />
-d @request_body <br />
</code>
</div>

#### Request body

```
{
    "type" : "jpg",
    "purpose" : "disputeEvidence"
}
```

#### Request parameters

<table width="100%" border="1">
    <tbody>
        <tr id='PDP9CAQSM5J'>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top; font-weight: bold; width: 30%;' class='bold'>Name
                <br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAkAlRX' style='vertical-align: top; font-weight: bold; width: 20%;' class='bold'>Location
                <br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAn6CQD' style='vertical-align: top; font-weight: bold; width: 50%;' class='bold'>Description
                <br /></td>
        </tr>
        <tr id='PDP9CAkesJe'>
            <td id='s:PDP9CAkesJe;PDP9CAXfdYQ' style='vertical-align: top;'>x-amz-pay-idempotency-key<br><b>(required)</b><br><br>Type: String
                <br /></td>
            <td id='s:PDP9CAkesJe;PDP9CAkAlRX' style='vertical-align: top;'>Header
                <br /></td>
            <td id='s:PDP9CAkesJe;PDP9CAn6CQD' style='vertical-align: top;'>Unique key to prevent duplicate uploads. For detailed guidance on creating and using idempotency keys, see Idempotency.
                <br /></td>
        </tr>
        <tr id='PDP9CAkesJe'>
            <td id='s:PDP9CAkesJe;PDP9CAXfdYQ' style='vertical-align: top;'>type<br><br>Type: String
                <br /></td>
            <td id='s:PDP9CAkesJe;PDP9CAkAlRX' style='vertical-align: top;'>Body
                <br /></td>
            <td id='s:PDP9CAkesJe;PDP9CAn6CQD' style='vertical-align: top;'>File format (jpg, png, pdf)
                <br /></td>
        </tr>
        <tr id='PDP9CAkesJe'>
            <td id='s:PDP9CAkesJe;PDP9CAXfdYQ' style='vertical-align: top;'>purpose<br><br>Type: String
                <br /></td>
            <td id='s:PDP9CAkesJe;PDP9CAkAlRX' style='vertical-align: top;'>Body
                <br /></td>
            <td id='s:PDP9CAkesJe;PDP9CAn6CQD' style='vertical-align: top;'>Upload reason (disputeEvidence)
                <br /></td>
        </tr>
    </tbody>
</table>

#### Supported file types

<table width="100%" border="1">
    <tbody>
        <tr id='PDP9CAQSM5J'>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top; font-weight: bold; width: 30%;' class='bold'>fileType<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top; font-weight: bold; width: 20%;' class='bold'>Description<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top; font-weight: bold; width: 50%;' class='bold'>Content-Type<br /></td>
        </tr>
        <tr id='PDP9CAkesJe'>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>csv<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>CSV files<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>text/csv<br /></td>
        </tr>
        <tr id='PDP9CAkesJe'>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>pdf<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>PDF documents<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>application/pdf<br /></td>
        </tr>
        <tr id='PDP9CAkesJe'>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>xls/xlsx<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>Excel spreadsheets<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>application/vnd.ms-excel (xls)<br />application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (xlsx)<br /></td>
        </tr>
        <tr id='PDP9CAkesJe'>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>doc/docx<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>Word documents<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>application/msword (doc)<br />application/vnd.openxmlformats-officedocument.wordprocessingml.document (docx)<br /></td>
        </tr>
        <tr id='PDP9CAkesJe'>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>ods<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>OpenDocument spreadsheets<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>application/vnd.oasis.opendocument.spreadsheet<br /></td>
        </tr>
        <tr id='PDP9CAkesJe'>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>jpg/png<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>Image files<br /></td>
            <td id='s:PDP9CAQSM5J;PDP9CAXfdYQ' style='vertical-align: top;'>image/jpeg (jpg)<br />image/png (png)<br /></td>
        </tr>
    </tbody>
</table>

#### Sample Code

<div style="display:none" class="environmentSpecificKeys">
<ul id="profileTabs" class="nav nav-tabs">
  <li class="nav-item"><a class="active nav-link noExtIcon" href="#phptab-uploadFile" data-toggle="tab">PHP</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#dotnettab-uploadFile" data-toggle="tab">.NET</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#javatab-uploadFile" data-toggle="tab">Java</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#nodejstab-uploadFile" data-toggle="tab">Node.js</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#rubytab-uploadFile" data-toggle="tab">Ruby</a></li>
</ul>
<div class="tab-content">
  <div role="tabpanel" class="tab-pane active" id="phptab-uploadFile">   
<div markdown="block">
```
<?php

    include 'vendor/autoload.php';

    $amazonpay_config = array(
        'public_key_id' => 'YOUR_PUBLIC_KEY_ID',
        'private_key'   => 'keys/private.pem', // Path to RSA Private Key (or a string representation)
        'region'        => 'YOUR_REGION_CODE',
        'algorithm'     => 'AMZN-PAY-RSASSA-PSS-V2'
    );

    $payload = array(
        'type' => 'jpg',
        'purpose' => 'disputeEvidence'
    );

    $headers = array('x-amz-pay-Idempotency-Key' => uniqid());

    try {
        $client = new Amazon\Pay\API\Client($amazonpay_config);
        $result = $client->uploadFile($payload, $headers);

        if ($result['status'] === 200) {
            $response = json_decode($result['response'], true);
            $fileId = $response['id'];
            $uploadUrl = $response['url'];

        } else {
            // check the error
            echo 'status=' . $result['status'] . '; response=' . $result['response'];
        }
    } catch (Exception $e) {
        // handle the exception
        echo $e;
    }
?>
```

</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="dotnettab-uploadFile">
<div markdown="block">
```
using Amazon.Pay.API.Types;
using Amazon.Pay.API.WebStore;
using Amazon.Pay.API.WebStore.File;
using Amazon.Pay.API.WebStore.Types;
using System;
using System.Collections.Generic;

public class Sample
{
    public WebStoreClient InitiateClient()
    {
        // set up config
        var payConfiguration = new ApiConfiguration
        (
            region: Region.YOUR_REGION_CODE,
            publicKeyId: "YOUR_PUBLIC_KEY_ID",
            privateKey: "PATH_OR_CONTENT_OF_YOUR_PRIVATE_KEY",
            algorithm: AmazonSignatureAlgorithm.V2
        );

        // init API client
        var client = new WebStoreClient(payConfiguration);

        return client;
    }

    public void UploadFile()
    {
        // prepare the request
        var request = new UploadFileRequest(type: "jpg", purpose: "disputeEvidence");

        // init Headers
        var myHeaderKey = "x-amz-pay-idempotency-key";
        var myHeaderValue = Guid.NewGuid().ToString();
        var headers = new Dictionary<string, string> { { myHeaderKey,  myHeaderValue } };

        // send the request
        FileResponse result = client.UploadFile(request, headers);

        // check if API call was successful
        if (!result.Success)
        {
            // handle the API error (use Status field to get the numeric error code)
        } else {
            // do something with the result, for instance:
            string fileId = result.Id;
            string uploadUrl = result.URL;
            DateTime urlExpiryTimestamp = result.UrlExpirationTimestamp;
        }
    }
}
```

</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="javatab-uploadFile">
<div markdown="block">
```
import com.amazon.pay.api.AmazonPayResponse;
import com.amazon.pay.api.PayConfiguration;
import com.amazon.pay.api.WebstoreClient;
import com.amazon.pay.api.exceptions.AmazonPayClientException;
import com.amazon.pay.api.types.DisputeFilePurpose;
import com.amazon.pay.api.types.EvidenceDocumentFileType;
import com.amazon.pay.api.types.Region;

import org.json.JSONObject;

// for generating an idempotency key
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public void sample() {
    PayConfiguration payConfiguration = null;
    try {
        payConfiguration = new PayConfiguration()
            .setPublicKeyId("YOUR_PUBLIC_KEY_ID")
            .setRegion(Region.YOUR_REGION_CODE)
            .setPrivateKey("YOUR_PRIVATE_KEY".toCharArray())
            .setAlgorithm("AMZN-PAY-RSASSA-PSS-V2");

        WebstoreClient webstoreClient = new WebstoreClient(payConfiguration);

        JSONObject payload = new JSONObject();
        payload.put("type", EvidenceDocumentFileType.JPG.getEvidenceDocumentFileType());
        payload.put("purpose", DisputeFilePurpose.DISPUTE_EVIDENCE.getDisputeFilePurpose());

        Map<String, String> header = new HashMap<String, String>();
        header.put("x-amz-pay-idempotency-key", UUID.randomUUID().toString().replace("-", ""));

        AmazonPayResponse response = webstoreClient.uploadFile(payload, header);
    } catch (AmazonPayClientException e) {
        e.printStackTrace();
    }
}
```

</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="nodejstab-uploadFile">
<div markdown="block">
```html
const fs = require('fs');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');
const uuidv4 = require('uuid/v4');

const config = {
    publicKeyId: 'YOUR_PUBLIC_KEY_ID',
    privateKey: fs.readFileSync('tst/private.pem'),
    region: 'YOUR_REGION_CODE',
    algorithm: 'AMZN-PAY-RSASSA-PSS-V2' 
};    

const payload = {
    type: "jpg",
    purpose: "disputeEvidence"
};

const headers = {
    'x-amz-pay-idempotency-key': uuidv4().toString().replace(/-/g, '')
};

const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.uploadFile(payload, headers);

response.then(function (result) {
    console.log(result.data);
}).catch(err => {
    console.log(err);
});
```

</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="rubytab-uploadFile">
<div markdown="block">
```
require 'amazon-pay-api-sdk-ruby'
require 'securerandom'

config = {
  region: 'YOUR_REGION_CODE', # Supported values: na, eu, jp
  public_key_id: 'YOUR_PUBLIC_KEY_ID',
  private_key: File.read('privateKey.pem')
}

client = AmazonPayClient.new(config)

payload = {
    "type": "jpg",
    "purpose": "disputeEvidence"
}

headers = {
    "x-amz-pay-Idempotency-Key": SecureRandom.uuid
}

response = client.upload_file(payload, headers: headers)

if response.code.to_i == 200
    puts response.body
else
    # check the error
    puts "status=#{response.code}"
    puts response.body
end
```

</div>
  </div>
</div>

</div>
<div style="display:none" class="notEnvironmentSpecificKeys">
<ul id="profileTabs" class="nav nav-tabs">
  <li class="nav-item"><a class="active nav-link noExtIcon" href="#phptab-uploadFile-NESK" data-toggle="tab">PHP</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#dotnettab-uploadFile-NESK" data-toggle="tab">.NET</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#javatab-uploadFile-NESK" data-toggle="tab">Java</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#nodejstab-uploadFile-NESK" data-toggle="tab">Node.js</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#rubytab-uploadFile-NESK" data-toggle="tab">Ruby</a></li>
</ul>
<div class="tab-content">
  <div role="tabpanel" class="tab-pane active" id="phptab-uploadFile-NESK">   
<div markdown="block">
```
<?php

    include 'vendor/autoload.php';

    $amazonpay_config = array(
        'public_key_id' => 'YOUR_PUBLIC_KEY_ID',
        'private_key'   => 'keys/private.pem', // Path to RSA Private Key (or a string representation)
        'region'        => 'YOUR_REGION_CODE',
        'sandbox'       => true,
        'algorithm'     => 'AMZN-PAY-RSASSA-PSS-V2'
    );

    $payload = array(
        'type' => 'jpg',
        'purpose' => 'disputeEvidence'
    );

    $headers = array('x-amz-pay-Idempotency-Key' => uniqid());

    try {
        $client = new Amazon\Pay\API\Client($amazonpay_config);
        $result = $client->uploadFile($payload, $headers);

        if ($result['status'] === 200) {
            $response = json_decode($result['response'], true);
            $fileId = $response['id'];
            $uploadUrl = $response['url'];

        } else {
            // check the error
            echo 'status=' . $result['status'] . '; response=' . $result['response'];
        }
    } catch (Exception $e) {
        // handle the exception
        echo $e;
    }
?>
```

</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="dotnettab-uploadFile-NESK">
<div markdown="block">
```
using Amazon.Pay.API.Types;
using Amazon.Pay.API.WebStore;
using Amazon.Pay.API.WebStore.File;
using Amazon.Pay.API.WebStore.Types;
using System;
using System.Collections.Generic;

public class Sample
{
    public WebStoreClient InitiateClient()
    {
        // set up config
        var payConfiguration = new ApiConfiguration
        (
            region: Region.YOUR_REGION_CODE,
            environment: Environment.Sandbox,
            publicKeyId: "YOUR_PUBLIC_KEY_ID",
            privateKey: "PATH_OR_CONTENT_OF_YOUR_PRIVATE_KEY",
            algorithm: AmazonSignatureAlgorithm.V2
        );

        // init API client
        var client = new WebStoreClient(payConfiguration);

        return client;
    }

    public void UploadFile()
    {
        // prepare the request
        var request = new UploadFileRequest(type: "jpg", purpose: "disputeEvidence");

        // init Headers
        var myHeaderKey = "x-amz-pay-idempotency-key";
        var myHeaderValue = Guid.NewGuid().ToString();
        var headers = new Dictionary<string, string> { { myHeaderKey,  myHeaderValue } };

        // send the request
        FileResponse result = client.UploadFile(request, headers);

        // check if API call was successful
        if (!result.Success)
        {
            // handle the API error (use Status field to get the numeric error code)
        } else {
            // do something with the result, for instance:
            string fileId = result.Id;
            string uploadUrl = result.URL;
            DateTime urlExpiryTimestamp = result.UrlExpirationTimestamp;
        }
    }
}
```

</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="javatab-uploadFile-NESK">
<div markdown="block">
```
import com.amazon.pay.api.AmazonPayResponse;
import com.amazon.pay.api.PayConfiguration;
import com.amazon.pay.api.WebstoreClient;
import com.amazon.pay.api.exceptions.AmazonPayClientException;
import com.amazon.pay.api.types.DisputeFilePurpose;
import com.amazon.pay.api.types.Environment;
import com.amazon.pay.api.types.EvidenceDocumentFileType;
import com.amazon.pay.api.types.Region;

import org.json.JSONObject;

// for generating an idempotency key
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public void sample() {
    PayConfiguration payConfiguration = null;
    try {
        payConfiguration = new PayConfiguration()
            .setPublicKeyId("YOUR_PUBLIC_KEY_ID")
            .setRegion(Region.YOUR_REGION_CODE)
            .setPrivateKey("YOUR_PRIVATE_KEY".toCharArray())
            .setEnvironment(Environment.SANDBOX)
            .setAlgorithm("AMZN-PAY-RSASSA-PSS-V2");

        WebstoreClient webstoreClient = new WebstoreClient(payConfiguration);

        JSONObject payload = new JSONObject();
        payload.put("type", EvidenceDocumentFileType.JPG.getEvidenceDocumentFileType());
        payload.put("purpose", DisputeFilePurpose.DISPUTE_EVIDENCE.getDisputeFilePurpose());

        Map<String, String> header = new HashMap<String, String>();
        header.put("x-amz-pay-idempotency-key", UUID.randomUUID().toString().replace("-", ""));

        AmazonPayResponse response = webstoreClient.uploadFile(payload, header);
    } catch (AmazonPayClientException e) {
        e.printStackTrace();
    }
}
```

</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="nodejstab-uploadFile-NESK">
<div markdown="block">
```html
const fs = require('fs');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');
const uuidv4 = require('uuid/v4');

const config = {
    publicKeyId: 'YOUR_PUBLIC_KEY_ID',
    privateKey: fs.readFileSync('tst/private.pem'),
    region: 'YOUR_REGION_CODE',
    sandbox: true,
    algorithm: 'AMZN-PAY-RSASSA-PSS-V2' 
};    

const payload = {
    type: "jpg",
    purpose: "disputeEvidence"
};

const headers = {
    'x-amz-pay-idempotency-key': uuidv4().toString().replace(/-/g, '')
};

const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.uploadFile(payload, headers);

response.then(function (result) {
    console.log(result.data);
}).catch(err => {
    console.log(err);
});
```

</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="rubytab-uploadFile-NESK">
<div markdown="block">
```
require 'amazon-pay-api-sdk-ruby'
require 'securerandom'

config = {
  region: 'YOUR_REGION_CODE', # Supported values: na, eu, jp
  public_key_id: 'YOUR_PUBLIC_KEY_ID',
  private_key: File.read('privateKey.pem'),
  sandbox: true
}

client = AmazonPayClient.new(config)

payload = {
    "type": "jpg",
    "purpose": "disputeEvidence"
}

headers = {
    "x-amz-pay-Idempotency-Key": SecureRandom.uuid
}

response = client.upload_file(payload, headers: headers)

if response.code.to_i == 200
    puts response.body
else
    # check the error
    puts "status=#{response.code}"
    puts response.body
end
```

</div>
  </div>
</div>

</div>

#### Response

The API returns:

```
{
    "id": "file_sdcjscbjckndjhckj",
    "type" : "jpg",
    "purpose": "disputeEvidence",
    "uploadTimestamp": "20190714T155300Z",
    "url": "https://pay-api.amazon.com/v1/files/file_sdcjscbjckndjhckj/contents",
    "urlExpirationTimeStamp": "20190714T155300Z"
}
```


#### Step 2: Upload your file

Send your file to the returned URL:

<code style="color: black">
curl "YOUR_PRESIGNED_URL" \ <br />
-X PUT \ <br />
-H "Content-Type: application/pdf" \ <br />
-T "/path/to/file" <br />
</code>

File Requirements:
* Maximum size: 2MB
* Files must be relevant dispute evidence

After uploading, use the returned fileId when submitting dispute evidence.

