Google Datastore large String upload #512
Answered
by
Byron
blackshadowsoftwareltd
asked this question in
Q&A
-
I am using
As per the documentation, I can not able to upload a large String (max 1,000,000 bytes). But I really need it. Is there any possible way to upload a larger string that is more than 1 MB? My Code Example. let key = Key {
partition_id: Some(PartitionId {
namespace_id: Some("".to_string()),
project_id: Some(PROJECT_ID.to_string()),
database_id: None,
// database_id: Some("default".to_string()),
}),
path: Some(vec![PathElement {
kind: Some(KIND_NAME.to_string()),
name: None,
..Default::default()
}]),
..Default::default()
};
let mut properties = HashMap::new();
properties.insert("name".to_string(), "Shop".to_db_value(false));
properties.insert("data".to_string(), dummy_json().as_str().to_db_value(true));
properties.insert("fromDate".to_string(), from_data.to_db_value());
properties.insert("toDate".to_string(), to_date.to_db_value());
let entity = Entity::new_entity(key, properties);
let mutation = Mutation::new_mutation(entity);
let commit_request = CommitRequest::new_commit_request(vec![mutation]);
let result = hub
.projects()
.commit(commit_request, PROJECT_ID)
.doit()
.await; pub trait ValueExt {
fn to_db_value(&self, is_index: bool) -> Value;
}
impl ValueExt for &str {
fn to_db_value(&self, exclude: bool) -> Value {
Value {
string_value: Some(self.to_string()),
exclude_from_indexes: Some(exclude),
..Default::default()
}
}
}
fn dummy_json() -> String {
let mut large_json = json!({});
for i in 1..=50000 {
let key = format!("key{}", i);
let value = format!("value{}", i);
large_json[key] = json!(value);
}
let json = large_json.to_string();
// Print the total bytes of the string
println!("Total bytes -> {}", json.as_str().to_string().len());
json
} |
Beta Was this translation helpful? Give feedback.
Answered by
Byron
Jun 18, 2024
Replies: 1 comment 1 reply
-
You will want to consult the official documentation site to see how this works, and then try to do the same with the API bindings. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
blackshadowsoftwareltd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You will want to consult the official documentation site to see how this works, and then try to do the same with the API bindings.