Class: Stripe::File

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List
Defined in:
lib/stripe/resources/file.rb

Overview

This object represents files hosted on Stripe’s servers. You can upload files with the [create file](stripe.com/docs/api#create_file) request (for example, when uploading dispute evidence). Stripe also creates files independently (for example, the results of a [Sigma scheduled query](stripe.com/docs/api#scheduled_queries)).

Related guide: [File upload guide](stripe.com/docs/file-upload)

Defined Under Namespace

Classes: CreateParams, ListParams

Constant Summary collapse

OBJECT_NAME =
"file"
OBJECT_NAME_ALT =

This resource can have two different object names. In latter API versions, only ‘file` is used, but since stripe-ruby may be used with any API version, we need to support deserializing the older `file_upload` object into the same class.

"file_upload"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Attribute Details

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.


101
102
103
# File 'lib/stripe/resources/file.rb', line 101

def created
  @created
end

#expires_atObject (readonly)

The file expires and isn’t available at this time in epoch seconds.


103
104
105
# File 'lib/stripe/resources/file.rb', line 103

def expires_at
  @expires_at
end

#filenameObject (readonly)

The suitable name for saving the file to a filesystem.


105
106
107
# File 'lib/stripe/resources/file.rb', line 105

def filename
  @filename
end

#idObject (readonly)

Unique identifier for the object.


107
108
109
# File 'lib/stripe/resources/file.rb', line 107

def id
  @id
end

A list of [file links](stripe.com/docs/api#file_links) that point at this file.


109
110
111
# File 'lib/stripe/resources/file.rb', line 109

def links
  @links
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.


111
112
113
# File 'lib/stripe/resources/file.rb', line 111

def object
  @object
end

#purposeObject (readonly)

The [purpose](stripe.com/docs/file-upload#uploading-a-file) of the uploaded file.


113
114
115
# File 'lib/stripe/resources/file.rb', line 113

def purpose
  @purpose
end

#sizeObject (readonly)

The size of the file object in bytes.


115
116
117
# File 'lib/stripe/resources/file.rb', line 115

def size
  @size
end

#titleObject (readonly)

A suitable title for the document.


117
118
119
# File 'lib/stripe/resources/file.rb', line 117

def title
  @title
end

#typeObject (readonly)

The returned file type (for example, ‘csv`, `pdf`, `jpg`, or `png`).


119
120
121
# File 'lib/stripe/resources/file.rb', line 119

def type
  @type
end

#urlObject (readonly)

Use your live secret API key to download the file from this URL.


121
122
123
# File 'lib/stripe/resources/file.rb', line 121

def url
  @url
end

Class Method Details

.create(params = {}, opts = {}) ⇒ Object

To upload a file to Stripe, you need to send a request of type multipart/form-data. Include the file you want to upload in the request, and the parameters for creating a file.

All of Stripe’s officially supported Client libraries support sending multipart/form-data.

[View source]

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/stripe/resources/file.rb', line 126

def self.create(params = {}, opts = {})
  if params[:file] && !params[:file].is_a?(String) && !params[:file].respond_to?(:read)
    raise ArgumentError, "file must respond to `#read`"
  end

  opts = { content_type: MultipartEncoder::MULTIPART_FORM_DATA }.merge(Util.normalize_opts(opts))

  request_stripe_object(
    method: :post,
    path: "/v1/files",
    params: params,
    opts: opts,
    base_address: :files
  )
end

.list(params = {}, opts = {}) ⇒ Object

Returns a list of the files that your account has access to. Stripe sorts and returns the files by their creation dates, placing the most recently created files at the top.

[View source]

143
144
145
# File 'lib/stripe/resources/file.rb', line 143

def self.list(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/files", params: params, opts: opts)
end

.object_nameObject

[View source]

17
18
19
# File 'lib/stripe/resources/file.rb', line 17

def self.object_name
  "file"
end

.object_name_altObject

[View source]

152
153
154
# File 'lib/stripe/resources/file.rb', line 152

def self.object_name_alt
  "file_upload"
end

.resource_urlObject

[View source]

156
157
158
# File 'lib/stripe/resources/file.rb', line 156

def self.resource_url
  "/v1/files"
end