MCPcopy Create free account
hub / github.com/BitVM/BitVM / upload_object

Method upload_object

bridge/src/client/data_store/sftp.rs:109–163  ·  view source on GitHub ↗
(
        &self,
        key: &str,
        data: &[u8],
        file_path: Option<&str>,
    )

Source from the content-addressed store, hash-verified

107 }
108
109 async fn upload_object(
110 &self,
111 key: &str,
112 data: &[u8],
113 file_path: Option<&str>,
114 ) -> Result<(), String> {
115 match connect(&self.credentials).await {
116 Ok(sftp) => {
117 match create_directories_if_non_existent(&sftp, file_path).await {
118 Ok(_) => {
119 let mut full_filename = key.to_string();
120 if file_path.is_some() {
121 full_filename = format!("{}/{}", file_path.unwrap(), key);
122 }
123 let result = sftp
124 .options()
125 .write(true)
126 .create_new(true)
127 .open(full_filename)
128 .await; // Use intermediate variable to prevent GC issue
129 match result {
130 Ok(_file) => {
131 let mut file = Box::pin(TokioCompatFile::from(_file));
132 match file.write(data).await {
133 Ok(_) => match file.flush().await {
134 Ok(_) => {
135 drop(file);
136 disconnect(sftp).await;
137 Ok(())
138 }
139 Err(err) => {
140 drop(file);
141 disconnect(sftp).await;
142 Err(format!("Unable to write {}: {}", key, err))
143 }
144 },
145 Err(err) => {
146 drop(file);
147 disconnect(sftp).await;
148 Err(format!("Unable to write {}: {}", key, err))
149 }
150 }
151 }
152 Err(err) => {
153 disconnect(sftp).await;
154 Err(format!("Unable to write {}: {}", key, err))
155 }
156 }
157 }
158 Err(err) => Err(format!("Unable to write {}: {}", key, err)),
159 }
160 }
161 Err(err) => Err(format!("Unable to write {}: {}", key, err)),
162 }
163 }
164}
165
166#[async_trait]

Callers 5

write_dataMethod · 0.45
test_sftpFunction · 0.45
test_ftpFunction · 0.45
test_ftpsFunction · 0.45

Calls 5

connectFunction · 0.85
lenMethod · 0.80
disconnectFunction · 0.70
flushMethod · 0.45

Tested by 3

test_sftpFunction · 0.36
test_ftpFunction · 0.36
test_ftpsFunction · 0.36