Hi @Aleksandar_Dimitrijevic and welcome in the MongoDB Community
!
I did a project like this. I was just writing the base64 image to my MongoDB Atlas cluster but maybe this can be a starting point:
exports = function(payload, response) {
const mongodb = context.services.get("mongodb-atlas");
const pictocat = mongodb.db("stitch").collection("pictocat");
var body = EJSON.parse(payload.body.text());
body.dateInserted = new Date();
pictocat.insertOne(body)
.then(result => {
response.setStatusCode(201);
});
};
I was sending the pictures like this:
#!/usr/bin/env bash
for i in {1..15}
do
start_json='{ "comment" : "This LOLCAT is awesome!", "picture" : { "$binary": { "base64": "';
base64_image=$(base64 -w 0 lolcat$i.jpg);
end_json='", "subType":"00"}}}';
json="${start_json}${base64_image}${end_json}"
curl -H "Content-Type: application/json" \
--data-binary @- \
https://webhooks.mongodb-stitch.com/api/client/v2.0/app/pictocat-kjvkr/service/REST/incoming_webhook/receive-cats?secret=test <<CURL_DATA
$json
CURL_DATA
done
As you can see, this script is a bit old because it was developed when MongoDB Realm was MongoDB Stitch so a few things might be different, but you get the idea.
To upload to S3, you now need to use the JS dependencies in Realm. They are touching this subject here.
Cheers,
Maxime.