This module contains endpoints and data types for basic file operations.
Summary
Functions
Copy a file or folder to a different location in the user's Dropbox. If the source path is a folder all its contents will be copied.
Create folder returns map
Same as create_folder/2 but returns {:ok, %Magpie.Folder{}}.
Delete the file or folder at a given path. If the path is a folder, all its contents will be deleted too. A successful response indicates that the file or folder was deleted. The returned metadata will be the corresponding FileMetadata or FolderMetadata for the item at time of deletion, and not a DeletedMetadata object.
Same as delete_folder/2 but returns {:ok, %Magpie.Folder{}}.
Download a file from a user's Dropbox.
Download a folder from the user's Dropbox as a zip file.
Export a file from the user's Dropbox to a portable format (for files that
cannot be downloaded directly, e.g. Paper docs). opts accepts
"export_format".
Returns the metadata for a file or folder.
Get a preview for a file.
Get a temporary link to stream content of a file. This link will expire in four hours and afterwards you will get 410 Gone. Content-Type of the link is determined automatically by the file's mime type.
Get a one-time-use temporary upload link for a direct binary upload.
commit_info takes the /files/upload argument fields, e.g.
%{"path" => "/a.txt", "mode" => "add"}; duration is in seconds.
Get a thumbnail for an image.
Get thumbnails for a list of images. We allow up to 25 thumbnails in a single batch.
Get a thumbnail for an image or document, addressed by path or shared link.
resource is %{".tag" => "path", "path" => ...} or
%{".tag" => "link", "url" => ...}; opts accepts "format", "size",
"mode" and "quality".
Move a file or folder to a different location in the user's Dropbox. If the source path is a folder all its contents will be moved.
Permanently delete the file or folder at a given path. Requires a Dropbox
Business account with Advanced or Enterprise plan. opts accepts
"parent_rev".
Restore a file to a specific revision.
Searches for files and folders.
Fetches the next page of search results returned from search/3.
Returns a lazy Stream over all search matches, fetching pages
through search/3 + search_continue/2 on demand. Raises
Magpie.Error if a page request fails.
Create a new file with the contents provided in the request.
Uploads the local file at local_path to path in the user's Dropbox,
picking the right strategy automatically
Functions
Copy a file or folder to a different location in the user's Dropbox. If the source path is a folder all its contents will be copied.
Example
Magpie.Files.copy(client, "/Temp/first", "/Tmp/second")
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-copy_v2
@spec create_folder(Magpie.Client.t(), binary()) :: any()
Create folder returns map
Example
Magpie.Files.create_folder client, "/Path"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-create_folder
@spec create_folder_to_struct(Magpie.Client.t(), binary()) :: {:ok, Magpie.Folder.t()} | {:error, Magpie.Error.t()}
Same as create_folder/2 but returns {:ok, %Magpie.Folder{}}.
Example
Magpie.Files.create_folder_to_struct client, "/Path"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-create_folder
Delete the file or folder at a given path. If the path is a folder, all its contents will be deleted too. A successful response indicates that the file or folder was deleted. The returned metadata will be the corresponding FileMetadata or FolderMetadata for the item at time of deletion, and not a DeletedMetadata object.
Example
Magpie.Files.delete_folder client, "/Homework/math/Prime_Numbers.txt"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-delete_v2
@spec delete_folder_to_struct(Magpie.Client.t(), binary()) :: {:ok, Magpie.Folder.t()} | {:error, Magpie.Error.t()}
Same as delete_folder/2 but returns {:ok, %Magpie.Folder{}}.
Example
Magpie.Files.delete_folder_to_struct client, "/Path"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-delete_v2
Download a file from a user's Dropbox.
Example
Magpie.Files.download client, "/mypdf.pdf"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-download
Download a folder from the user's Dropbox as a zip file.
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-download_zip
Export a file from the user's Dropbox to a portable format (for files that
cannot be downloaded directly, e.g. Paper docs). opts accepts
"export_format".
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-export
Returns the metadata for a file or folder.
Example
Magpie.Files.get_metadata client, "/mypdf.pdf"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata
Get a preview for a file.
Example
Magpie.Files.get_preview client, "/mypdf.pdf"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_preview
Get a temporary link to stream content of a file. This link will expire in four hours and afterwards you will get 410 Gone. Content-Type of the link is determined automatically by the file's mime type.
Example
Magpie.Files.get_temporary_link client, "/video.mp4"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_preview
Get a one-time-use temporary upload link for a direct binary upload.
commit_info takes the /files/upload argument fields, e.g.
%{"path" => "/a.txt", "mode" => "add"}; duration is in seconds.
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_temporary_upload_link
Get a thumbnail for an image.
Example
Magpie.Files.get_thumbnail client, "/image.jpg"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail
Get thumbnails for a list of images. We allow up to 25 thumbnails in a single batch.
Example
batch = %{ "path" => "/image.jpg", "format" => "jpeg", "size" => "w64h64"} entries = [batch] Magpie.Files.get_thumbnail_batch client, entries
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail_batch
Get a thumbnail for an image or document, addressed by path or shared link.
resource is %{".tag" => "path", "path" => ...} or
%{".tag" => "link", "url" => ...}; opts accepts "format", "size",
"mode" and "quality".
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail_v2
Move a file or folder to a different location in the user's Dropbox. If the source path is a folder all its contents will be moved.
Example
Magpie.Files.move(client, "/Homework/math", "/Homework/algebra")
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-move_v2
Permanently delete the file or folder at a given path. Requires a Dropbox
Business account with Advanced or Enterprise plan. opts accepts
"parent_rev".
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-permanently_delete
Restore a file to a specific revision.
Example
Magpie.Files.restore(client, "/root/word.docx", "a1c10ce0dd78")
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-restore
Searches for files and folders.
options accepts the SearchOptions fields, e.g.
%{"path" => "/Photos", "max_results" => 100, "filename_only" => true}.
Example
Magpie.Files.search(client, "word.docx", %{"path" => "/root"})
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-search_v2
Fetches the next page of search results returned from search/3.
Example
Magpie.Files.search_continue(client, cursor)
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-search-continue_v2
Returns a lazy Stream over all search matches, fetching pages
through search/3 + search_continue/2 on demand. Raises
Magpie.Error if a page request fails.
Example
client
|> Magpie.Files.search_stream("report", %{"path" => "/Work"})
|> Enum.take(50)
Create a new file with the contents provided in the request.
Example
Magpie.Files.upload client, "/mypdf.pdf", "/mypdf.pdf"
More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-upload
Uploads the local file at local_path to path in the user's Dropbox,
picking the right strategy automatically:
- files up to
:session_thresholdbytes go through a single/files/uploadcall; - larger files are streamed through an upload session
(
start→append_v2× N →finish) in chunks of:chunk_sizebytes, without ever loading the whole file into memory.
Returns {:ok, file_metadata} on success, {:error, %Magpie.Error{}} on
Dropbox errors, or {:error, posix} when the local file cannot be read.
Options
:chunk_size— upload session chunk size in bytes (default 8 MiB):session_threshold— size above which an upload session is used (default 150 MiB, the Dropbox limit for single-request uploads):mode—"add"(default) or"overwrite":autorename— defaulttrue:mute— defaultfalse
Example
{:ok, metadata} = Magpie.Files.upload_file(client, "/Backup/db.dump", "priv/db.dump")