Corona SDK : Files

cloud:upload

Signature

cloud:upload(local_source[, listener[, remote_base_dir[, baseDirectory[, headers]]]])

Parameters

Name Description Type Default Required
local_source The source name of the file to upload. string nil Y
listener The upload progress listener. function nil N
remote_base_dir Optional directory to place the file on the server. string /files N
baseDirectory The Corona base directory constant system.DocumentsDirectory N
headers A table of additional headers to send. table nil N

Returns

A network event object id.

Example

-- CoronaSDK/main.lua
require('coronium.cloud'):new({
  host = "123.123.123.123",
  project_key = "00000000-0000-0000-000000000"
})

local function listener(event)
  if event.phase == 'began' then
    print('Starting Upload')
  elseif event.phase == 'progress'
    print('Uploading...')
    print(event.bytesTransferred)
  elseif event.phase == "ended" then
    if not event.response.error then
      print(event.response.baseDirectory)
      print(event.response.filename)
    else
      --error
      print(event.response.error)
    end
  end
end

local req = cloud:upload('local_file.png', listener)

cloud:download

Signature

cloud:download(remote_path, local_path[, listener[, baseDirectory[, headers]]])

Parameters

Name Description Type Default Required
remote_path The file path relative to the Cloud /files directory string nil Y
local_path A local filepath destination for the file. string nil N
listener The download progress listener function nil N
baseDirectory The Corona SDK starting directory. constant system.DocumentsDirectory N
headers Additional headers to add to the request. table nil N

Returns

A network event object id.

Example

-- CoronaSDK/main.lua
require('coronium.cloud'):new({
  host = "123.123.123.123",
  project_key = "00000000-0000-0000-000000000"
})

local function listener(event)
  if event.phase == 'began' then
    print('Started download...')
  elseif event.phase == 'progress' then
    print('Downloading...')
    print(event.bytesTransferred)
  elseif event.phase == "ended" then
    print('Download done')
    print( event.response.filename )
    print( event.response.baseDirectory )
  end
end

local req = cloud:download('file.png', 'my_file.png', listener)