Files

Type Alias Files 

Source
pub type Files = Resource<FileMetadata>;
Expand description

Files store documents, binary blobs, and other file data and relate it to assets.

Aliased Type§

pub struct Files {
    pub api_client: Arc<ApiClient>,
    /* private fields */
}

Fields§

§api_client: Arc<ApiClient>

A reference to the shared API Client.

Implementations§

Source§

impl Files

Source

pub async fn upload_stream<S>( &self, mime_type: &str, url: &str, stream: S, stream_chunked: bool, ) -> Result<()>
where S: TryStream + Send + 'static, S::Error: Into<Box<dyn Error + Send + Sync>>, Bytes: From<S::Ok>,

Upload a stream to a url, the url is received from Files::upload

§Arguments
  • mime_type - Mime type of file to upload. For example application/pdf.
  • url - URL to upload stream to.
  • stream - Stream to upload.
  • stream_chunked - Set this to true to use chunked streaming. Note that this is not supported for the azure file backend. If this is set to false, the entire file is read into memory before uploading, which may be very expensive. Use upload_stream_known_size if the size of the file is known.
§Example
use tokio_util::codec::{BytesCodec, FramedRead};

let file = tokio::fs::File::open("my-file");
let stream = FramedRead::new(file, BytesCodec::new());
cognite_client.files.upload_stream(&file.mime_type.unwrap(), &file.upload_url, stream, true).await?;

Note that stream_chunked being true is in general more efficient, but it is not supported for the azure file backend.

Source

pub async fn upload_stream_known_size<S>( &self, mime_type: &str, url: &str, stream: S, size: u64, ) -> Result<()>
where S: TryStream + Send + 'static, S::Error: Into<Box<dyn Error + Send + Sync>>, Bytes: From<S::Ok>,

Upload a stream to an url, the url is received from Files::upload This method requires that the length of the stream in bytes is known before hand. If the specified size is wrong, the request may fail or even hang.

§Arguments
  • mime_type - Mime type of file to upload. For example application/pdf.
  • url - URL to upload stream to.
  • stream - Stream to upload.
  • size - Known size of stream in bytes. Note: Do not use this method if the size is not actually known!
§Example
use tokio_util::codec::{BytesCodec, FramedRead};

let file = tokio::fs::File::open("my-file").await?;
let size = file.metadata().await?.len();
let stream = FramedRead::new(file, BytesCodec::new());

cognite_client.files.upload_stream_known_size(&file_res.mime_type.unwrap(), &file_res.extra.upload_url, stream, size).await?;

Note that this will still stream the data from disk, so it should be as efficient as upload_stream with upload_chunked, but not require the target to accept content-encoding: chunked.

Source

pub async fn upload_file( &self, mime_type: &str, url: &str, file: File, ) -> Result<()>

Upload a file as a stream to CDF. url should be the upload URL returned from upload.

§Arguments
  • mime_type - Mime type of file to upload. For example application/pdf.
  • url - URL to upload the file to.
  • file - File to upload.
Source

pub async fn upload_blob( &self, mime_type: &str, url: &str, blob: impl Into<Bytes>, ) -> Result<()>

Upload a binary vector to url.

§Arguments
  • mime_type - Mime type of file to upload. For example application/pdf.
  • url - URL to upload blob to.
  • blob - File to upload, as bytes.
Source

pub async fn upload( &self, overwrite: bool, item: &AddFile, ) -> Result<FileUploadResult<UploadUrl>>

Create a file, optionally overwriting an existing file.

The result will contain an upload URL that can be used to upload a file.

§Arguments
  • overwrite - Set this to true to overwrite existing files with the same external_id. If this is false, and a file with the given external_id already exists, the request will fail.
  • item - The file to upload.

Get an upload link for a file with given identity.

§Arguments

id - Identity of file metadata or data models file.

Get multipart upload link for an existing file metadata or data models file.

§Arguments
  • id - Identity of file metadata or data models file.
  • parts - Number of parts to be uploaded.
Source

pub async fn multipart_upload<'a>( &'a self, overwrite: bool, parts: u32, item: &AddFile, ) -> Result<(MultipartUploader<'a>, FileMetadata)>

Create a file, specifying that it should be uploaded in multiple parts.

This returns a MultipartUploader, which wraps the upload process.

§Arguments
  • overwrite - Set this to true to overwrite existing files with the same external_id. If this is false, and a file with the given external_id already exists, the request will fail.
  • parts - The number of parts to upload, should be a number between 1 and 250.
  • item - The file to upload.
Source

pub async fn multipart_upload_existing<'a>( &'a self, id: &IdentityOrInstance, parts: u32, ) -> Result<(MultipartUploader<'a>, FileMetadata)>

Upload files for an existing file metadata or data models file.

This returns a MultipartUploader, which wraps the upload process.

§Arguments
  • parts - The number of parts to upload, should be a number between 1 and 250.
  • id - Identity of file metadata or data models file.
Source

pub async fn init_multipart_upload( &self, overwrite: bool, parts: u32, item: &AddFile, ) -> Result<FileUploadResult<MultiUploadUrls>>

Create a file, specifying that it should be uploaded in multiple parts.

§Arguments
  • overwrite - Set this to true to overwrite existing files with the same external_id. If this is false, and a file with the given external_id already exists, the request will fail.
  • parts - The number of parts to upload, should be a number between 1 and 250.
  • item - The file to upload.
Source

pub async fn complete_multipart_upload( &self, id: IdentityOrInstance, upload_id: String, ) -> Result<()>

Complete a multipart upload. This endpoint must be called after all parts of a multipart file upload have been uploaded.

§Arguments
  • id - ID of the file that was uploaded.
  • upload_id - upload_id returned by init_multipart_upload.

Get download links for a list of files.

§Arguments
  • ids - List of file IDs or external IDs.
Source

pub async fn download( &self, url: &str, ) -> Result<impl TryStream<Ok = Bytes, Error = Error>>

Stream a file from url.

§Arguments
  • url - URL to download from.
Source

pub async fn download_file( &self, id: IdentityOrInstance, ) -> Result<impl TryStream<Ok = Bytes, Error = Error>>

Stream a file given by id.

§Arguments
  • id - ID or external ID of file to download.

Trait Implementations§

Source§

impl CleanResource<FileMetadata> for Files

Source§

async fn clean_resource( &self, resources: Vec<FileMetadata>, ) -> Result<(), Error>

Delete the provided resources.
Source§

impl<R> DeleteWithIgnoreUnknownIds<IdentityList<R>> for Files
where IdentityList<R>: Serialize, R: Send + Sync,

Source§

fn delete( &self, deletes: impl Into<TIdt> + Send, ignore_unknown_ids: bool, ) -> impl Future<Output = Result<()>> + Send
where Self: Sync,

Delete a list of resources, optionally ignore unknown ids. Read more
Source§

impl FilterWithRequest<PartitionedFilter<FileFilter>, FileMetadata> for Files

Source§

fn filter( &self, filter: TFilter, ) -> impl Future<Output = Result<ItemsVec<TResponse, Cursor>>> + Send

Filter resources. Read more
Source§

fn filter_all( &self, filter: TFilter, ) -> impl Future<Output = Result<Vec<TResponse>>> + Send
where TFilter: SetCursor, TResponse: Send,

Filter resources, following cursors until they are exhausted. Read more
Source§

fn filter_all_stream( &self, filter: TFilter, ) -> impl TryStream<Ok = TResponse, Error = Error, Item = Result<TResponse>> + Send
where TFilter: SetCursor, TResponse: Send + 'static,

Filter resources, following cursors. This returns a stream, you can abort the stream whenever you want and only resources retrieved up to that point will be returned. Read more
Source§

fn filter_all_partitioned( &self, filter: TFilter, num_partitions: u32, ) -> impl Future<Output = Result<Vec<TResponse>>> + Send
where TFilter: SetCursor + WithPartition, TResponse: Send,

Filter resources using partitioned reads, following cursors until all partitions are exhausted. Read more
Source§

fn filter_all_partitioned_stream( &self, filter: TFilter, num_partitions: u32, ) -> impl TryStream<Ok = TResponse, Error = Error, Item = Result<TResponse>> + Send
where TFilter: SetCursor + WithPartition, TResponse: Send + 'static,

Filter resources using partitioned reads, following cursors until all partitions are exhausted. This returns a stream. Read more
Source§

impl<R> RetrieveWithIgnoreUnknownIds<IdentityOrInstanceList<R>, FileMetadata> for Files

Source§

fn retrieve( &self, ids: impl Into<TIdt> + Send, ignore_unknown_ids: bool, ) -> impl Future<Output = Result<Vec<TResponse>>> + Send

Retrieve a list of items from CDF. If ignore_unknown_ids is false, this will fail if any items are missing from CDF. Read more
Source§

impl SearchItems<'_, FileFilter, FileSearch, FileMetadata> for Files

Source§

fn search( &'a self, filter: TFilter, search: TSearch, limit: Option<u32>, ) -> impl Future<Output = Result<Vec<TResponse>>> + Send

Fuzzy search resources. Read more
Source§

impl Update<Patch<PatchFile>, FileMetadata> for Files

Source§

fn update( &self, updates: &[TUpdate], ) -> impl Future<Output = Result<Vec<TResponse>>> + Send

Update a list of resources. Read more
Source§

fn update_from<'a, T>( &self, updates: &'a [T], ) -> impl Future<Output = Result<Vec<TResponse>>> + Send
where T: Sync + Clone + 'a, TUpdate: From<T>,

Update a list of resources by converting to the update from a different type. Read more
Source§

fn update_ignore_unknown_ids( &self, updates: &[TUpdate], ) -> impl Future<Output = Result<Vec<TResponse>>> + Send
where TUpdate: EqIdentity, TResponse: Send,

Update a list of resources, ignoring any that fail due to items missing in CDF. Read more
Source§

fn update_from_ignore_unknown_ids<'a, T>( &self, updates: &'a [T], ) -> impl Future<Output = Result<Vec<TResponse>>> + Send
where T: Sync + Clone + 'a, TUpdate: From<T> + EqIdentity, TResponse: Send,

Update a list of resources by converting from a different type, ignoring any that fail due items missing in CDF. Read more
Source§

impl WithBasePath for Files

Source§

const BASE_PATH: &'static str = "files"

Base path for this resource type.