Files

The File and Folder resources allow you to operate on files and folders. While the two resources are similar, they are not exactly the same, so pay close attention to the documentation to ensure that you are operating on the correct resource for the operation you are trying to perform.

Download File

SDK Method

file.DownloadToFile()

Return Values

Returns a files_sdk.File value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

Function Arguments

ArgumentDescription
params
FileDownloadParams
Required
Download request parameters.
filePath
string
Required
Local path to download the file to.

FileDownloadParams Fields

FieldDescription
Path
string
Required
Path to operate on.

Download File

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

client := file.Client{Config: files_sdk.GlobalConfig}
filePath := "file-to-download.txt"
fileEntry, err := client.DownloadToFile(
    files_sdk.FileDownloadParams{
      Path: "file-to-download.txt",
    },
    filePath,
)
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(fileEntry.Path)

Upload File

SDK Method

file.Upload()

Return Values

Returns an error, or nil on success.

Authorization Requirement

Available to all authenticated keys or sessions.

Function Arguments

ArgumentDescription
options
array(UploadOption)
Required
Upload options.

Upload Options

OptionDescription
UploadWithDestinationPathThe destination path to upload the file to.
UploadWithFileThe local path to the file to upload.
UploadWithReaderA reader to upload the file from.
UploadWithContextThe context to upload the file with.

Upload File

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

client := file.Client{Config: files_sdk.GlobalConfig}
sourcePath := "file-to-upload.txt"
destinationPath := "file-to-upload.txt"
err := client.Upload(
    file.UploadWithFile(sourcePath),
    file.UploadWithDestinationPath(destinationPath),
)
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}

Find File/Folder by Path

SDK Method

file.Find()

Return Values

Returns a files_sdk.File value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileFindParams Fields

FieldDescription
Path
string
Required
Path to operate on.
PreviewSize
string
Request a preview size. Can be small (default), large, xlarge, or pdf.
WithPreviews
boolean
Include file preview information?
WithPriorityColor
boolean
Include file priority color information?

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

file, err := file.Find(files_sdk.FileFindParams{Path: "path"})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(file)

List Folders by Path

For historical reasons, and to maintain compatibility with a variety of other cloud-based MFT and EFSS services, Folders will always be listed before Files when listing a Folder. This applies regardless of the sorting parameters you provide. These will be used, after the initial sort application of Folders before Files.

SDK Method

folder.ListFor()

Return Values

Returns a *folder.Iter and an error. Range over All() to receive files_sdk.File values and errors. Check each loop error before using its resource. Next() and Err() remain supported.

Authorization Requirement

Available to all authenticated keys or sessions.

FolderListForParams Fields

FieldDescription
Path
string
Required
Path to operate on.
PreviewSize
string
Request a preview size. Can be small (default), large, xlarge, or pdf.
Search
string
If specified, will search the folders/files list by name. Ignores text before last /. This is the same API used by the search bar in the web UI when running 'Search This Folder'. Search results are a best effort, not real time, and not guaranteed to perfectly match the latest folder listing. Results may be truncated if more than 1,000 possible matches exist. This field should only be used for ad-hoc (human) searching, and not as part of an automated process.
SearchCustomMetadataKey
string
If provided, the search string in search will search for files where this custom metadata key matches the value sent in search. Set this to * to allow any metadata key to match the value sent in search.
SearchAll
boolean
Search entire site? If true, we will search the entire site. Do not provide a path when using this parameter. The search term must contain at least 3 characters after replacing * with spaces and trimming leading and trailing whitespace. This is the same API used by the search bar in the web UI when running 'Search All Files'. Search results are a best effort, not real time, and not guaranteed to match every file. This field should only be used for ad-hoc (human) searching, and not as part of an automated process.
WithPreviews
boolean
Include file previews?
WithPriorityColor
boolean
Include file priority color information?
Type
string
Type of objects to return. Can be folder or file.
ModifiedAtDatetime
string
If provided, will only return files/folders modified after this time. Can be used only in combination with type filter.

Additional Arguments

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/folder"
)

fileIterator, err := folder.ListFor(files_sdk.FolderListForParams{Path: "path"})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}

for file, err := range fileIterator.All() {
    if err != nil {
        var respErr files_sdk.ResponseError
        if errors.As(err, &respErr) {
            fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
        } else {
            fmt.Printf("Request failed: %v\n", err)
        }
        return
    }
    fmt.Println(file)
}

Create Folder

SDK Method

folder.Create()

Return Values

Returns a files_sdk.File value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FolderCreateParams Fields

FieldDescription
Path
string
Required
Path to operate on.
MkdirParents
boolean
Create parent directories if they do not exist?
ProvidedMtime
string
User provided modification time.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/folder"
)

file, err := folder.Create(files_sdk.FolderCreateParams{Path: "path"})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(file)

Update File/Folder Metadata

SDK Method

file.Update()

Return Values

Returns a files_sdk.File value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileUpdateParams Fields

FieldDescription
Path
string
Required
Path to operate on.
CustomMetadata
object
Custom metadata map. Replaces existing metadata; an empty map clears it. Requires Full or Admin permission. Uploaders with Write permission can supply custom metadata when completing an upload instead.
ProvidedMtime
string
Modified time of file.
PriorityColor
string
Priority/Bookmark color of file.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

file, err := file.Update(files_sdk.FileUpdateParams{
  Path: "path",
  CustomMetadata: map[string]interface{}{"department": "finance"},
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(file)

Delete File/Folder

SDK Method

file.Delete()

Return Values

Returns an error, or nil on success.

Authorization Requirement

Available to all authenticated keys or sessions.

FileDeleteParams Fields

FieldDescription
Path
string
Required
Path to operate on.
Recursive
boolean
If true, will recursively delete folders. Otherwise, will error on non-empty folders.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

err := file.Delete(files_sdk.FileDeleteParams{Path: "path"})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}

Create a ZIP from one or more paths and save it to a destination path

SDK Method

file.Zip()

Return Values

Returns a files_sdk.FileAction value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileZipParams Fields

FieldDescription
Paths
array(string)
Required
Paths to include in the ZIP.
Destination
string
Required
Destination file path for the ZIP.
ArchiveFormat
string
Archive format to create.
Possible values: zip, tar, tar.gz, tgz
Overwrite
boolean
Overwrite existing file in the destination?

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

fileAction, err := file.Zip(files_sdk.FileZipParams{
  Paths: "paths",
  Destination: "destination",
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(fileAction)

Extract a ZIP file to a destination folder

SDK Method

file.Unzip()

Return Values

Returns a files_sdk.FileAction value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileUnzipParams Fields

FieldDescription
Path
string
Required
ZIP file path to extract.
Destination
string
Required
Destination folder path for extracted files.
Filename
string
Optional single entry filename to extract.
Overwrite
boolean
Overwrite existing files in the destination?

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

fileAction, err := file.Unzip(files_sdk.FileUnzipParams{
  Path: "path",
  Destination: "destination",
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(fileAction)

Encrypt a file with GPG and save it to a destination path

SDK Method

file.GpgEncrypt()

Return Values

Returns a files_sdk.FileAction value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileGpgEncryptParams Fields

FieldDescription
Path
string
Required
Path to operate on.
Destination
string
Required
Destination file path for the encrypted file.
GpgKeyIds
array(int64)
GPG Key IDs to encrypt with.
GpgKeyPartnerId
int64
Partner ID whose GPG keys should be used for encryption.
SigningKeyId
int64
Optional GPG Key ID to sign with.
Armor
boolean
Output ASCII-armored encrypted data.
Overwrite
boolean
Overwrite existing file in the destination?

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

fileAction, err := file.GpgEncrypt(files_sdk.FileGpgEncryptParams{
  Path: "path",
  Destination: "destination",
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(fileAction)

Decrypt a GPG-encrypted file and save it to a destination path

SDK Method

file.GpgDecrypt()

Return Values

Returns a files_sdk.FileAction value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileGpgDecryptParams Fields

FieldDescription
Path
string
Required
Path to operate on.
Destination
string
Required
Destination file path for the decrypted file.
GpgKeyIds
array(int64)
GPG Key IDs to decrypt with. If omitted, every accessible private GPG key in the source workspace is used.
GpgKeyPartnerId
int64
Partner ID whose GPG keys should be used for decryption.
UseAllPrivateKeys
boolean
Use every accessible private GPG key in the source workspace for decryption.
IgnoreMdcError
boolean
Ignore errors from the MDC (modification detection code) check.
Overwrite
boolean
Overwrite existing file in the destination?

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

fileAction, err := file.GpgDecrypt(files_sdk.FileGpgDecryptParams{
  Path: "path",
  Destination: "destination",
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(fileAction)

Transform a file and save the output to a destination path

SDK Method

file.Transform()

Return Values

Returns a files_sdk.FileAction value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileTransformParams Fields

FieldDescription
Path
string
Required
Path to operate on.
Destination
string
Required
Destination file path for the transformed output.
TransformType
string
Required
Transform type. Supported values are image_convert, document_convert, and files_transform_script_execute.
TargetFormat
string
Required
Destination format to create.
Script
string
Files TransformScript source. Required when transform_type is files_transform_script_execute.
Width
int64
Maximum output width for image_convert.
Height
int64
Maximum output height for image_convert.
Overwrite
boolean
Overwrite existing file in the destination?

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

fileAction, err := file.Transform(files_sdk.FileTransformParams{
  Path: "path",
  Destination: "destination",
  TransformType: "transform_type",
  TargetFormat: "target_format",
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(fileAction)

Move File/Folder

SDK Method

file.Move()

Return Values

Returns a files_sdk.FileAction value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileMoveParams Fields

FieldDescription
Path
string
Required
Path to operate on.
Destination
string
Required
Move destination path.
Overwrite
boolean
Overwrite existing file(s) in the destination?

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

fileAction, err := file.Move(files_sdk.FileMoveParams{
  Path: "path",
  Destination: "destination",
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(fileAction)

Copy File/Folder

SDK Method

file.Copy()

Return Values

Returns a files_sdk.FileAction value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileCopyParams Fields

FieldDescription
Path
string
Required
Path to operate on.
Destination
string
Required
Copy destination path.
CopyBehaviors
boolean
If copying a folder, also copy supported behaviors, email notification subscriptions, and per-folder branding to the destination folder tree?
Structure
boolean
Copy structure only?
Overwrite
boolean
Overwrite existing file(s) in the destination?

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

fileAction, err := file.Copy(files_sdk.FileCopyParams{
  Path: "path",
  Destination: "destination",
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(fileAction)

Delete File/Folder and return its File Action. A pending or processing deletion continues in the background after this returns; check its File Migration for completion. Waiting for the File Migration does not cancel the deletion

SDK Method

file.BeginDelete()

Return Values

Returns a files_sdk.FileAction value and an error.

Authorization Requirement

Available to all authenticated keys or sessions.

FileBeginDeleteParams Fields

FieldDescription
Path
string
Required
Path to operate on.
Recursive
boolean
If true, will recursively delete folders. Otherwise, will error on non-empty folders.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/file"
)

fileAction, err := file.BeginDelete(files_sdk.FileBeginDeleteParams{Path: "path"})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Printf("API error (%s): %s\n", respErr.Type, respErr.ErrorMessage)
    } else {
        fmt.Printf("Request failed: %v\n", err)
    }
    return
}
fmt.Println(fileAction)

Upload to External Destinations

These SDK helpers upload files into external destinations without requiring callers to assemble destination-specific paths manually.

DestinationSDK MethodID Parameter
Remote ServerUploadToRemoteServerremoteServerID
SnapshotUploadToSnapshotsnapshotID
Child SiteUploadToChildSitesiteID

Example Request

err := client.UploadToRemoteServer(remoteServerID, "remote/path/to/file.txt", file.UploadWithFile(sourcePath))
err = client.UploadToSnapshot(snapshotID, "remote/path/to/file.txt", file.UploadWithFile(sourcePath))
err = client.UploadToChildSite(siteID, "remote/path/to/file.txt", file.UploadWithFile(sourcePath))

Copy to External Destinations

These SDK helpers copy files or folders into external destinations without requiring callers to assemble destination-specific paths manually.

DestinationSDK MethodID Parameter
Remote ServerCopyToRemoteServerremoteServerID
SnapshotCopyToSnapshotsnapshotID
Child SiteCopyToChildSitesiteID

Example Request

_, err := client.CopyToRemoteServer(files_sdk.FileCopyParams{Path: sourcePath, Overwrite: lib.Bool(true)}, remoteServerID, "remote/path/to/file.txt")
_, err = client.CopyToSnapshot(files_sdk.FileCopyParams{Path: sourcePath}, snapshotID, "remote/path/to/file.txt")
_, err = client.CopyToChildSite(files_sdk.FileCopyParams{Path: sourcePath}, siteID, "remote/path/to/file.txt")

Move to External Destinations

These SDK helpers move files or folders into external destinations without requiring callers to assemble destination-specific paths manually.

DestinationSDK MethodID Parameter
Remote ServerMoveToRemoteServerremoteServerID
SnapshotMoveToSnapshotsnapshotID
Child SiteMoveToChildSitesiteID

Example Request

_, err := client.MoveToRemoteServer(files_sdk.FileMoveParams{Path: sourcePath, Overwrite: lib.Bool(true)}, remoteServerID, "remote/path/to/file.txt")
_, err = client.MoveToSnapshot(files_sdk.FileMoveParams{Path: sourcePath}, snapshotID, "remote/path/to/file.txt")
_, err = client.MoveToChildSite(files_sdk.FileMoveParams{Path: sourcePath}, siteID, "remote/path/to/file.txt")

The File Object

Some of the methods above return a File object. The attributes of this object are listed below.

AttributeDescription
Path
string
File/Folder path. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.
CreatedById
int64
User ID of the User who created the file/folder
CreatedByApiKeyId
int64
ID of the API key that created the file/folder
CreatedByAs2IncomingMessageId
int64
ID of the AS2 Incoming Message that created the file/folder
CreatedByAutomationId
int64
ID of the Automation that created the file/folder
CreatedByBundleRegistrationId
int64
ID of the Bundle Registration that created the file/folder
CreatedByInboxId
int64
ID of the Inbox that created the file/folder
CreatedByRemoteServerId
int64
ID of the Remote Server that created the file/folder
CreatedBySyncId
int64
ID of the Sync that created the file/folder
CustomMetadata
object
Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
DisplayName
string
File/Folder display name
Type
string
Type: directory or file.
Size
int64
File/Folder size
CreatedAt
date-time
File created date/time
LastModifiedById
int64
User ID of the User who last modified the file/folder
LastModifiedByApiKeyId
int64
ID of the API key that last modified the file/folder
LastModifiedByAutomationId
int64
ID of the Automation that last modified the file/folder
LastModifiedByBundleRegistrationId
int64
ID of the Bundle Registration that last modified the file/folder
LastModifiedByRemoteServerId
int64
ID of the Remote Server that last modified the file/folder
LastModifiedBySyncId
int64
ID of the Sync that last modified the file/folder
Mtime
date-time
File last modified date/time, according to the server. This is the timestamp of the last Files.com operation of the file, regardless of what modified timestamp was sent.
ProvidedMtime
date-time
File last modified date/time, according to the client who set it. Files.com allows desktop, FTP, SFTP, and WebDAV clients to set modified at times. This allows Desktop<->Cloud syncing to preserve modified at times.
Crc32
string
File CRC32 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
Md5
string
File MD5 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
Sha1
string
File SHA1 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
Sha256
string
File SHA256 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
MimeType
string
MIME Type. This is determined by the filename extension and is not stored separately internally.
Region
string
Region location
Permissions
string
A short string representing the current user's permissions. Can be r (Read),w (Write),d (Delete), l (List) or any combination
SubfoldersLocked
boolean
Are subfolders locked and unable to be modified?
IsLocked
boolean
Is this folder locked and unable to be modified?
DownloadUri
string
Link to download file. Provided only in response to a download request.
DirectConnectionInfo
DirectConnectionInfo
Optional direct connection information for direct Agent transfer attempts
PriorityColor
string
Bookmark/priority color of file/folder
PreviewId
int64
File preview ID
Preview
Preview
File preview

custom_metadata

Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.

Value typeDescription
object of string valuesCustom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value. At most 32 keys.

Example custom_metadata

{
  "department": "finance"
}