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
impl Files
Sourcepub async fn upload_stream<S>(
&self,
mime_type: &str,
url: &str,
stream: S,
stream_chunked: bool,
) -> Result<()>
pub async fn upload_stream<S>( &self, mime_type: &str, url: &str, stream: S, stream_chunked: bool, ) -> Result<()>
Upload a stream to a url, the url is received from Files::upload
§Arguments
mime_type- Mime type of file to upload. For exampleapplication/pdf.url- URL to upload stream to.stream- Stream to upload.stream_chunked- Set this totrueto use chunked streaming. Note that this is not supported for the azure file backend. If this is set tofalse, the entire file is read into memory before uploading, which may be very expensive. Useupload_stream_known_sizeif 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.
Sourcepub async fn upload_stream_known_size<S>(
&self,
mime_type: &str,
url: &str,
stream: S,
size: u64,
) -> Result<()>
pub async fn upload_stream_known_size<S>( &self, mime_type: &str, url: &str, stream: S, size: u64, ) -> Result<()>
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 exampleapplication/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.
Sourcepub async fn upload_file(
&self,
mime_type: &str,
url: &str,
file: File,
) -> Result<()>
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 exampleapplication/pdf.url- URL to upload the file to.file- File to upload.
Sourcepub async fn upload_blob(
&self,
mime_type: &str,
url: &str,
blob: impl Into<Bytes>,
) -> Result<()>
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 exampleapplication/pdf.url- URL to upload blob to.blob- File to upload, as bytes.
Sourcepub async fn upload(
&self,
overwrite: bool,
item: &AddFile,
) -> Result<FileUploadResult<UploadUrl>>
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 totrueto overwrite existing files with the sameexternal_id. If this isfalse, and a file with the givenexternal_idalready exists, the request will fail.item- The file to upload.
Sourcepub async fn get_upload_link(
&self,
id: &IdentityOrInstance,
) -> Result<FileUploadResult<UploadUrl>>
pub async fn get_upload_link( &self, id: &IdentityOrInstance, ) -> Result<FileUploadResult<UploadUrl>>
Get an upload link for a file with given identity.
§Arguments
id - Identity of file metadata or data models file.
Sourcepub async fn get_multipart_upload_link(
&self,
id: &IdentityOrInstance,
parts: u32,
) -> Result<FileUploadResult<MultiUploadUrls>>
pub async fn get_multipart_upload_link( &self, id: &IdentityOrInstance, parts: u32, ) -> Result<FileUploadResult<MultiUploadUrls>>
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.
Sourcepub async fn multipart_upload<'a>(
&'a self,
overwrite: bool,
parts: u32,
item: &AddFile,
) -> Result<(MultipartUploader<'a>, FileMetadata)>
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 totrueto overwrite existing files with the sameexternal_id. If this isfalse, and a file with the givenexternal_idalready 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.
Sourcepub async fn multipart_upload_existing<'a>(
&'a self,
id: &IdentityOrInstance,
parts: u32,
) -> Result<(MultipartUploader<'a>, FileMetadata)>
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.
Sourcepub async fn init_multipart_upload(
&self,
overwrite: bool,
parts: u32,
item: &AddFile,
) -> Result<FileUploadResult<MultiUploadUrls>>
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 totrueto overwrite existing files with the sameexternal_id. If this isfalse, and a file with the givenexternal_idalready 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.
Sourcepub async fn complete_multipart_upload(
&self,
id: IdentityOrInstance,
upload_id: String,
) -> Result<()>
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_idreturned byinit_multipart_upload.