Previously, i was able to store a base64 image using GridFsTemplate as below.
val imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary("base64 image string")
gridFsTemplate.store(ByteArrayInputStream(imageBytes), "imagename")
However the store() function of ReactiveGridFsTemplate takes in a parameter which is of type Flux<DataBuffer>. How can i convert a base64 image to that type?
I believe you can use AsyncStreamHelper.toAsyncInputStream with the base64 as a byte array.
I'm on my phone right now so I can't write an example, but you can check the second last method of the class here: https://github.com/BayviewComputerClub/smoothie-web/blob/master/src/main/java/club/bayview/smoothieweb/repositories/TestDataRepository.java
Related
I'd like to convert a json into the data type that is supported by Azure Form Recognizer. I'm able to convert the data type into a dic and then into a json but I'm not able to do the opposite without analysing once again the document. How could I use the data type supported by Azure Form Recognizer without having to analyse the document more than one time?
Here is what I have.
endpoint = "endpoint"
key = "key"
# create your `DocumentAnalysisClient` instance and `AzureKeyCredential` variable
document_analysis_client = DocumentAnalysisClient(endpoint=endpoint, credential=AzureKeyCredential(key))
# Extract text from doc using "prebuilt-document"
with open("file.pdf", "rb") as f:
poller = document_analysis_client.begin_analyze_document(
"prebuilt-document", document=f)
result = poller.result()
import json
form_pages = poller.result()
d = form_pages.to_dict()
json_string = json.dumps(d)
print(json_string)
data = json.loads(json_string)
poller1 = form_pages.from_dict(data)
What's the scenario for converting the JSON model representation back to the SDK model? The operations don't take the result models as an input, as a solution the original result model be stored somewhere until it needs to be used again in that case.
Also, for converting the model to JSON, it would be better to use the AzureJSONEncoder to that the SDK can properly serialize all types. For example:
from azure.core.serialization import AzureJSONEncoder
# save the dictionary as JSON content in a JSON file, use the AzureJSONEncoder
# to help make types, such as dates, JSON serializable
# NOTE: AzureJSONEncoder is only available with azure.core>=1.18.0.
with open('data.json', 'w') as f:
json.dump(analyze_result_dict, f, cls=AzureJSONEncoder)
Here is a link to the full sync sample: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2/sample_convert_to_and_from_dict.py
i would like to convert an image to Base64-encoded in esp32 cam . already i used method under detail like this :
ConvertBase64("D:/ok.jpg","D:/edcodedFolder");
but not working (edcodedFolder is empty)
maybe another/right way is using method under detail :
static String encode(const uint8_t * data, size_t length, bool doNewLines = true);
but i dont know how to use above method .
would you please help me?
finaly i found solution under detail that works fine
String encrypt = base64::encode(fb->buf, fb->len);
I have a String based Key-Value Array inside of a String, and I want to decoded it and assign the value to an existing array in Swift 4.2. For example:
let array: [String:String] = []
let stringToDecode = “[\“Hello\”:\”World\”, \"Key\":\"Value\"]”
// I want ‘array’ to be assigned
// to the value that is inside
// ‘stringToDecode’
I’ve tried the JSON decoder, but it couldn’t decode it. Is there a simple way to do this? Thank you.
Try using a library like SwiftyJson, it makes working with json much easier.
I have a json string to build a query, and I need to convert this to QueryBuilder. (ES Ver. 6.3.0)
I found that I can use wrapperQuery method, so I wrote this code:
String str = cond.getFilter().toString();
QueryBuilder filter = QueryBuilders.boolQuery().must(QueryBuilders.wrapperQuery(str));
And these are result of variables in debug mode:
This method is working right, as the decription in the Docs(https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wrapper-query.html)
The problem is, that this query just not working.
What is wrong and what should I do?
Any comments would be appreciated. Thanks.
Your JSON format seems to be wrong. Since your ASSET_IP is not a number, it must be string in JSON representation. Hence you need to put it as below in your JSON.
{ "ASSET_IP" : "xx.xxx.xxx.xx" }
Update your JSON with the above and try again.
I've got a set of data that exists in memory in a CSV format. I have this method in my controller:
public FileContentResult ItemsAsExcelExport(){
var model = _itemService.GetExcelExportModel();
return new FileContentResult(model.CSVData, model.MimeType){FileDownloadName = model.FileName};
}
The problem here is that my model.CSVData property returns a simple comma delimited set of values. I'm not sure how I can satisfy the fileContents argument of the FileContentResult contructor. It's asking for a byte array.
Thanks in advance.
Take a look at this question How do I get a consistent byte representation of strings in C# without manually specifying an encoding?
The solution is
byte[] b1 = System.Text.Encoding.UTF8.GetBytes (myString);