Module: Parse::API::Files

Included in:
Client
Defined in:
lib/parse/api/files.rb

Overview

Defines the Parse Files interface for the Parse REST API

Instance Method Summary collapse

Instance Method Details

#create_file(fileName, data = {}, content_type = nil, **opts) ⇒ Parse::Response

Upload and create a Parse file.

Parameters:

  • fileName (String)

    the basename of the file.

  • data (Hash) (defaults to: {})

    the data related to this file.

  • content_type (String) (defaults to: nil)

    the mime-type of the file.

  • opts (Hash)

    additional options forwarded to Client#request (e.g. :session_token, :use_master_key). When the SDK is running in client mode against a Parse Server with fileUpload.enableForAuthenticatedUser on, a session_token is required for the upload to be accepted.

Returns:



23
24
25
26
27
28
29
30
# File 'lib/parse/api/files.rb', line 23

def create_file(fileName, data = {}, content_type = nil, **opts)
  safe = Parse::API::PathSegment.file!(fileName, kind: "file name")
  headers = {}
  headers.merge!({ Parse::Protocol::CONTENT_TYPE => content_type.to_s }) if content_type.present?
  response = request :post, "#{FILES_PATH}/#{safe}", body: data, headers: headers, opts: opts
  response.parse_class = Parse::Model::TYPE_FILE
  response
end