VB.NET Stripe: Create a File Upload

Back to Index

Uploads a file to Stripe.

Documentation: https://stripe.com/docs/api/curl#create_file_upload

CURL Command

curl https://files.stripe.com/v1/files \
   -u STRIPE_SECRET_KEY: \
   -F purpose=dispute_evidence \
   -F file="@/path/to/a/file.jpg"

VB.NET Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

'  URL: https://files.stripe.com/v1/files
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect("files.stripe.com",port,bTls,bAutoReconnect)
If (success <> True) Then
    Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
End If


rest.SetAuthBasic("STRIPE_SECRET_KEY","")

rest.PartSelector = "1"
rest.AddHeader("Content-Disposition","form-data; name=""purpose""")
rest.SetMultipartBodyString("dispute_evidence")

rest.PartSelector = "2"
Dim fileStream2 As New Chilkat.Stream
fileStream2.SourceFile = "/path/to/a/file.jpg"
rest.AddHeader("Content-Disposition","form-data; name=""/path/to/a/file.jpg""; filename=""/path/to/a/file.jpg""")
rest.AddHeader("Content-Type","image/jpeg")
rest.SetMultipartBodyStream(fileStream2)


rest.PartSelector = "0"

rest.AddHeader("Expect","100-continue")

Dim strResponseBody As String = rest.FullRequestMultipart("POST","/v1/files")
If (rest.LastMethodSuccess <> True) Then
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
End If


Dim jsonResponse As New Chilkat.JsonObject
jsonResponse.Load(strResponseBody)

Dim id As String
Dim object As String
Dim created As Integer
Dim filename As String
Dim purpose As String
Dim size As Integer
Dim type As String
Dim url As String

id = jsonResponse.StringOf("id")
object = jsonResponse.StringOf("object")
created = jsonResponse.IntOf("created")
filename = jsonResponse.StringOf("filename")
purpose = jsonResponse.StringOf("purpose")
size = jsonResponse.IntOf("size")
type = jsonResponse.StringOf("type")
url = jsonResponse.StringOf("url")

Sample JSON Response Body

{
  "id": "file_1BnEEuGswQrCoh0XqB3XkqAg",
  "object": "file_upload",
  "created": 1516661888,
  "filename": "path",
  "purpose": "sigma_scheduled_query",
  "size": 500,
  "type": "csv",
  "url": "https://stripe-upload-api.s3.amazonaws.com/uploads/file_1BnEEuGswQrCoh0XqB3XkqAg?AWSAccessKeyId=KEY_ID\u0026Expires=TIMESTAMP\u0026Signature=SIGNATURE"
}